File tree 2 files changed +12
-5
lines changed
2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 99
99
maybe_box_native ,
100
100
maybe_convert_platform ,
101
101
maybe_downcast_to_dtype ,
102
- maybe_infer_to_datetimelike ,
103
102
validate_numeric_casting ,
104
103
)
105
104
from pandas .core .dtypes .common import (
147
146
from pandas .core .arrays .sparse import SparseFrameAccessor
148
147
from pandas .core .construction import (
149
148
extract_array ,
149
+ sanitize_array ,
150
150
sanitize_masked_array ,
151
151
)
152
152
from pandas .core .generic import (
@@ -4226,7 +4226,7 @@ def _sanitize_column(self, value) -> ArrayLike:
4226
4226
4227
4227
# possibly infer to datetimelike
4228
4228
if is_object_dtype (value .dtype ):
4229
- value = maybe_infer_to_datetimelike (value )
4229
+ value = sanitize_array (value , None )
4230
4230
4231
4231
else :
4232
4232
value = construct_1d_arraylike_from_scalar (value , len (self ), dtype = None )
Original file line number Diff line number Diff line change @@ -421,19 +421,26 @@ def test_setitem_intervals(self):
421
421
422
422
# B & D end up as Categoricals
423
423
# the remainer are converted to in-line objects
424
- # contining an IntervalIndex.values
424
+ # containing an IntervalIndex.values
425
425
df ["B" ] = ser
426
426
df ["C" ] = np .array (ser )
427
427
df ["D" ] = ser .values
428
428
df ["E" ] = np .array (ser .values )
429
+ df ["F" ] = ser .astype (object )
429
430
430
431
assert is_categorical_dtype (df ["B" ].dtype )
431
432
assert is_interval_dtype (df ["B" ].cat .categories )
432
433
assert is_categorical_dtype (df ["D" ].dtype )
433
434
assert is_interval_dtype (df ["D" ].cat .categories )
434
435
435
- assert is_object_dtype (df ["C" ])
436
- assert is_object_dtype (df ["E" ])
436
+ # Thes goes through the Series constructor and so get inferred back
437
+ # to IntervalDtype
438
+ assert is_interval_dtype (df ["C" ])
439
+ assert is_interval_dtype (df ["E" ])
440
+
441
+ # But the Series constructor doesn't do inference on Series objects,
442
+ # so setting df["F"] doesnt get cast back to IntervalDtype
443
+ assert is_object_dtype (df ["F" ])
437
444
438
445
# they compare equal as Index
439
446
# when converted to numpy objects
You can’t perform that action at this time.
0 commit comments