Skip to content

BUG GH23451 Allow setting date in string index for Series #23495

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

Merged
merged 4 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ Datetimelike
- Bug in :func:`DataFrame.combine` with datetimelike values raising a TypeError (:issue:`23079`)
- Bug in :func:`date_range` with frequency of ``Day`` or higher where dates sufficiently far in the future could wrap around to the past instead of raising ``OutOfBoundsDatetime`` (:issue:`14187`)
- Bug in :class:`PeriodIndex` with attribute ``freq.n`` greater than 1 where adding a :class:`DateOffset` object would return incorrect results (:issue:`23215`)
- Bug in :class:`Series` that interpreted string indices as lists of characters when setting datetimelike values (:issue:`23451`)

Timedelta
^^^^^^^^^
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ def _set_with(self, key, value):
except Exception:
pass

if not isinstance(key, (list, Series, np.ndarray, Series)):
if is_scalar(key):
key = [key]
elif not isinstance(key, (list, Series, np.ndarray)):
try:
key = list(key)
except Exception:
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_datetime_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,10 @@ def test_minmax_nat_series(self, nat):
def test_minmax_nat_dataframe(self, nat):
assert nat.min()[0] is pd.NaT
assert nat.max()[0] is pd.NaT

def test_setitem_with_string_index(self):
# GH 23451
x = pd.Series([1, 2, 3], index=['Date', 'b', 'other'])
x['Date'] = date.today()
assert x.Date == date.today()
assert x['Date'] == date.today()