Setting values on Series using .loc with a TZ-aware DatetimeIndex fails #12050

Closed
coroa opened this Issue Jan 15, 2016 · 2 comments

Comments

Projects
None yet
3 participants
Contributor

coroa commented Jan 15, 2016

In [1]: import pandas as pd

In [2]: index = pd.date_range('2011-01-01', '2011-01-02', tz='utc')   # without tz='utc' it works

In [3]: index
Out[3]: DatetimeIndex(['2011-01-01', '2011-01-02'], dtype='datetime64[ns, UTC]', freq='D')

In [4]: s = pd.Series(range(2), index=index)

In [5]: s.loc[index] = 5
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-5-992315c98f0d> in <module>()
----> 1 s.loc[index] = 5

/usr/lib/python2.7/dist-packages/pandas/core/indexing.pyc in __setitem__(self, key, value)
    114 
    115     def __setitem__(self, key, value):
--> 116         indexer = self._get_setitem_indexer(key)
    117         self._setitem_with_indexer(indexer, value)
    118 

/usr/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _get_setitem_indexer(self, key)
    109 
    110         try:
--> 111             return self._convert_to_indexer(key, is_setter=True)
    112         except TypeError:
    113             raise IndexingError(key)

/usr/lib/python2.7/dist-packages/pandas/core/indexing.pyc in _convert_to_indexer(self, obj, axis, is_setter)
   1148                 mask = check == -1
   1149                 if mask.any():
-> 1150                     raise KeyError('%s not in index' % objarr[mask])
   1151 
   1152                 return _values_from_object(indexer)

KeyError: "['2011-01-01T01:00:00.000000000+0100' '2011-01-02T01:00:00.000000000+0100'] not in index"

On python 2.7.11, pandas 0.17.1, linux.

Contributor

jreback commented Jan 15, 2016

so getitem and .loc getting working as well as setitem, but setting with .loc seems broken (only with list-likes).

In [9]: s[index]
Out[9]: 
2011-01-01 00:00:00+00:00    0
2011-01-02 00:00:00+00:00    1
Freq: D, dtype: int64

In [10]: s.loc[index]
Out[10]: 
2011-01-01 00:00:00+00:00    0
2011-01-02 00:00:00+00:00    1
Freq: D, dtype: int64

In [11]: s[index] = 5

In [12]: s
Out[12]: 
2011-01-01 00:00:00+00:00    5
2011-01-02 00:00:00+00:00    5
Freq: D, dtype: int64

# setting single items
In [14]: s.loc[index[0]] = 10

In [15]: s
Out[15]: 
2011-01-01 00:00:00+00:00    10
2011-01-02 00:00:00+00:00     5
Freq: D, dtype: int64

jreback added this to the 0.18.0 milestone Jan 15, 2016

Contributor

jreback commented Jan 19, 2016

closed by #12054

jreback closed this Jan 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment