Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
maybe_box_native,
maybe_convert_platform,
maybe_downcast_to_dtype,
maybe_infer_to_datetimelike,
validate_numeric_casting,
)
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -4045,7 +4044,7 @@ def _sanitize_column(self, value) -> ArrayLike:

# possibly infer to datetimelike
if is_object_dtype(value.dtype):
value = maybe_infer_to_datetimelike(value)
value = Series(value)._values

else:
value = construct_1d_arraylike_from_scalar(value, len(self), dtype=None)
Expand Down
13 changes: 10 additions & 3 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,26 @@ def test_setitem_intervals(self):

# B & D end up as Categoricals
# the remainer are converted to in-line objects
# contining an IntervalIndex.values
# containing an IntervalIndex.values
df["B"] = ser
df["C"] = np.array(ser)
df["D"] = ser.values
df["E"] = np.array(ser.values)
df["F"] = ser.astype(object)

assert is_categorical_dtype(df["B"].dtype)
assert is_interval_dtype(df["B"].cat.categories)
assert is_categorical_dtype(df["D"].dtype)
assert is_interval_dtype(df["D"].cat.categories)

assert is_object_dtype(df["C"])
assert is_object_dtype(df["E"])
# Thes goes through the Series constructor and so get inferred back
# to IntervalDtype
assert is_interval_dtype(df["C"])
assert is_interval_dtype(df["E"])

# But the Series constructor doesn't do inference on Series objects,
# so setting df["F"] doesnt get cast back to IntervalDtype
assert is_object_dtype(df["F"])

# they compare equal as Index
# when converted to numpy objects
Expand Down