Skip to content

Series with dtype=object does unexpected type conversion #39285

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 10 commits into from
Jan 28, 2021
Merged
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
12 changes: 12 additions & 0 deletions pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,18 @@ def test_setitem_empty_series_datetimeindex_preserves_freq(self):
tm.assert_series_equal(series, expected)
assert series.index.freq == expected.index.freq

def test_setitem_empty_series_timestamp_preserves_dtype(self):
# GH 21881
timestamp = Timestamp(1412526600000000000)
series = Series([timestamp], index=["timestamp"], dtype=object)
expected = series["timestamp"]

series = Series([], dtype=object)
series["anything"] = 300.0
series["timestamp"] = timestamp
result = series["timestamp"]
assert result == expected


def test_setitem_scalar_into_readonly_backing_data():
# GH#14359: test that you cannot mutate a read only buffer
Expand Down