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

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

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

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

coroa opened this issue Jan 15, 2016 · 2 comments
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Regression Functionality that used to work in a prior pandas version Timezones Timezone data dtype
Milestone

Comments

@coroa
Copy link
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.

@jreback
Copy link
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 jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype labels Jan 15, 2016
@jreback jreback added this to the 0.18.0 milestone Jan 15, 2016
@jorisvandenbossche jorisvandenbossche added the Regression Functionality that used to work in a prior pandas version label Jan 19, 2016
@jreback
Copy link
Contributor

jreback commented Jan 19, 2016

closed by #12054

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 Regression Functionality that used to work in a prior pandas version Timezones Timezone data dtype
Projects
None yet
Development

No branches or pull requests

3 participants