Skip to content

BUG: at/iat __setitem__ failing to cast #39582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ Indexing
- Bug in incorrectly raising in :meth:`Index.insert`, when setting a new column that cannot be held in the existing ``frame.columns``, or in :meth:`Series.reset_index` or :meth:`DataFrame.reset_index` instead of casting to a compatible dtype (:issue:`39068`)
- Bug in :meth:`RangeIndex.append` where a single object of length 1 was concatenated incorrectly (:issue:`39401`)
- Bug in setting ``numpy.timedelta64`` values into an object-dtype :class:`Series` using a boolean indexer (:issue:`39488`)
- Bug in setting numeric values into a into a boolean-dtypes :class:`Series` using ``at`` or ``iat`` failing to cast to object-dtype (:issue:`39582`)
-

Missing
^^^^^^^
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,17 +1043,17 @@ def _set_value(self, label, value, takeable: bool = False):
Scalar value.
takeable : interpret the index as indexers, default False
"""
try:
if takeable:
self._values[label] = value
else:
if not takeable:
try:
loc = self.index.get_loc(label)
validate_numeric_casting(self.dtype, value)
self._values[loc] = value
except KeyError:
except KeyError:
# set using a non-recursive method
self.loc[label] = value
return
else:
loc = label

# set using a non-recursive method
self.loc[label] = value
self._set_values(loc, value)

# ----------------------------------------------------------------------
# Unsorted
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ def test_int_key(self, obj, key, expected, val, indexer_sli):

self.check_indexer(obj, key, expected, val, indexer_sli)

if indexer_sli is tm.loc:
self.check_indexer(obj, key, expected, val, tm.at)
elif indexer_sli is tm.iloc:
self.check_indexer(obj, key, expected, val, tm.iat)

rng = range(key, key + 1)
self.check_indexer(obj, rng, expected, val, indexer_sli)

Expand Down