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

Can't put date in Series if index is a string longer than 1 character #23451

Closed
emberlightstudios opened this issue Nov 1, 2018 · 1 comment · Fixed by #23495
Closed

Can't put date in Series if index is a string longer than 1 character #23451

emberlightstudios opened this issue Nov 1, 2018 · 1 comment · Fixed by #23495
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timeseries
Milestone

Comments

@emberlightstudios
Copy link

emberlightstudios commented Nov 1, 2018

Code Sample

>>> import pandas
>>> x = pandas.Series([1,2,3],  index=['Date','b','other'])
>>> x
Date     1
b        2
other    3
dtype: int64
>>> from datetime import date
>>> x.Date = date.today()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\pandas\core\generic.py", line 4405, in __setattr__
    self[name] = value
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 939, in __setitem__
    setitem(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 935, in setitem
    self._set_with(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 983, in _set_with
    self._set_labels(key, value)
  File "C:\Python37\lib\site-packages\pandas\core\series.py", line 993, in _set_labels
    raise ValueError('%s not contained in the index' % str(key[mask]))
ValueError: ['D' 'a' 't' 'e'] not contained in the index
>>> x.b = date.today()
>>> x.b
datetime.date(2018, 11, 1)
>>> x
Date              1
b        2018-11-01
other             3
dtype: object
>>>

Problem description

I cannot put a date object in a Series if the index is a string with len > 1.
It works if it's only a single character. Other types seem to work. I've only seen the problem with dates.

@mroeschke
Copy link
Member

This looks similar to #12862, and I can reproduce this in master as well.

@mroeschke mroeschke added Bug Timeseries Indexing Related to indexing on series/frames, not to indexes themselves labels Nov 1, 2018
@jreback jreback added this to the 0.24.0 milestone Nov 5, 2018
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 Timeseries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants