Skip to content
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

BUG: setitem on string dtype with slices fails #31772

Closed
jorisvandenbossche opened this issue Feb 7, 2020 · 0 comments · Fixed by #31773
Closed

BUG: setitem on string dtype with slices fails #31772

jorisvandenbossche opened this issue Feb 7, 2020 · 0 comments · Fixed by #31773
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jorisvandenbossche
Copy link
Member

In [33]: df = pd.DataFrame({'A': ['a', 'b', 'c']}, dtype='string')   

In [34]: df.loc[0:, 'A'] = "test"  
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-34-bc65087be9d7> in <module>
----> 1 df.loc[0:, 'A'] = "test"

~/scipy/pandas/pandas/core/indexing.py in __setitem__(self, key, value)
    629             key = com.apply_if_callable(key, self.obj)
    630         indexer = self._get_setitem_indexer(key)
--> 631         self._setitem_with_indexer(indexer, value)
    632 
    633     def _validate_key(self, key, axis: int):

~/scipy/pandas/pandas/core/indexing.py in _setitem_with_indexer(self, indexer, value)
   1014             # actually do the set
   1015             self.obj._consolidate_inplace()
-> 1016             self.obj._data = self.obj._data.setitem(indexer=indexer, value=value)
   1017             self.obj._maybe_update_cacher(clear=True)
   1018 

~/scipy/pandas/pandas/core/internals/managers.py in setitem(self, **kwargs)
    538 
    539     def setitem(self, **kwargs):
--> 540         return self.apply("setitem", **kwargs)
    541 
    542     def putmask(self, **kwargs):

~/scipy/pandas/pandas/core/internals/managers.py in apply(self, f, filter, **kwargs)
    417                 applied = b.apply(f, **kwargs)
    418             else:
--> 419                 applied = getattr(b, f)(**kwargs)
    420             result_blocks = _extend_blocks(applied, result_blocks)
    421 

~/scipy/pandas/pandas/core/internals/blocks.py in setitem(self, indexer, value)
   1801 
   1802         check_setitem_lengths(indexer, value, self.values)
-> 1803         self.values[indexer] = value
   1804         return self
   1805 

~/scipy/pandas/pandas/core/arrays/string_.py in __setitem__(self, key, value)
    260                 raise ValueError("Must provide strings.")
    261 
--> 262         super().__setitem__(key, value)
    263 
    264     def fillna(self, value=None, method=None, limit=None):

~/scipy/pandas/pandas/core/arrays/numpy_.py in __setitem__(self, key, value)
    273             value = np.asarray(value, dtype=self._ndarray.dtype)
    274 
--> 275         self._ndarray[key] = value
    276 
    277     def __len__(self) -> int:

IndexError: arrays used as indices must be of integer (or boolean) type
@jorisvandenbossche jorisvandenbossche added this to the 1.0.2 milestone Feb 7, 2020
@jbrockmendel jbrockmendel added the Indexing Related to indexing on series/frames, not to indexes themselves label Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants