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
matt-seaton opened this issue Nov 1, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@matt-seaton
Copy link

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

This comment has been minimized.

Copy link
Member

commented Nov 1, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.