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

Series.__setitem__ on DatetimeTZ values with tuples in the index fails #20441

Closed
TomAugspurger opened this issue Mar 21, 2018 · 0 comments · Fixed by #27367
Closed

Series.__setitem__ on DatetimeTZ values with tuples in the index fails #20441

TomAugspurger opened this issue Mar 21, 2018 · 0 comments · Fixed by #27367
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype
Milestone

Comments

@TomAugspurger
Copy link
Contributor

A bit of an edge case

In [1]: import pandas as pd

In [2]: arr = pd.date_range('2017', periods=4, tz='US/Eastern')

In [3]: s = pd.Series(arr, index=[(0, 1), (0, 2), (0, 3), (0, 4)])

In [4]: s[(0, 1)] = float('NaN')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/sandbox/pandas-ip/pandas/pandas/core/series.py in setitem(key, value)
    871             try:
--> 872                 self._set_with_engine(key, value)
    873                 return

~/sandbox/pandas-ip/pandas/pandas/core/series.py in _set_with_engine(self, key, value)
    930         try:
--> 931             self.index._engine.set_value(values, key, value)
    932             return

TypeError: Argument 'arr' has incorrect type (expected numpy.ndarray, got DatetimeIndex)

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-4-0a0fdcf8dcd6> in <module>()
----> 1 s[(0, 1)] = float('NaN')

~/sandbox/pandas-ip/pandas/pandas/core/series.py in __setitem__(self, key, value)
    922         # do the setitem
    923         cacher_needs_updating = self._check_is_chained_assignment_possible()
--> 924         setitem(key, value)
    925         if cacher_needs_updating:
    926             self._maybe_update_cacher()

~/sandbox/pandas-ip/pandas/pandas/core/series.py in setitem(key, value)
    904                 if (isinstance(key, tuple) and
    905                         not isinstance(self.index, MultiIndex)):
--> 906                     raise ValueError("Can only tuple-index with a MultiIndex")
    907
    908                 # python 3 type errors should be raised

ValueError: Can only tuple-index with a MultiIndex

xref #19907 (comment)

@TomAugspurger TomAugspurger added Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype Difficulty Advanced labels Mar 21, 2018
@jreback jreback modified the milestones: 0.24.2, 0.25.0 Feb 16, 2019
@jreback jreback modified the milestones: 0.25.0, 1.0 Apr 20, 2019
@jreback jreback modified the milestones: 1.0, 0.25.0 Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype
Projects
None yet
2 participants