@@ -170,15 +170,6 @@ def test_setitem_boolean_python_list(self, func):
170
170
expected = Series (["a" , "b" , "c" ])
171
171
tm .assert_series_equal (ser , expected )
172
172
173
- @pytest .mark .parametrize ("value" , [None , NaT , np .nan ])
174
- def test_setitem_boolean_td64_values_cast_na (self , value ):
175
- # GH#18586
176
- series = Series ([0 , 1 , 2 ], dtype = "timedelta64[ns]" )
177
- mask = series == series [0 ]
178
- series [mask ] = value
179
- expected = Series ([NaT , 1 , 2 ], dtype = "timedelta64[ns]" )
180
- tm .assert_series_equal (series , expected )
181
-
182
173
def test_setitem_boolean_nullable_int_types (self , any_nullable_numeric_dtype ):
183
174
# GH: 26468
184
175
ser = Series ([5 , 6 , 7 , 8 ], dtype = any_nullable_numeric_dtype )
@@ -643,62 +634,43 @@ def is_inplace(self):
643
634
return True
644
635
645
636
646
- class TestSetitemNATimedelta64Dtype (SetitemCastingEquivalents ):
647
- # some nat-like values should be cast to timedelta64 when inserting
648
- # into a timedelta64 series. Others should coerce to object
649
- # and retain their dtypes.
650
-
651
- @pytest .fixture
652
- def obj (self ):
653
- return Series ([0 , 1 , 2 ], dtype = "m8[ns]" )
637
+ class TestSetitemNADatetimeLikeDtype (SetitemCastingEquivalents ):
638
+ # some nat-like values should be cast to datetime64/timedelta64 when
639
+ # inserting into a datetime64/timedelta64 series. Others should coerce
640
+ # to object and retain their dtypes.
641
+ # GH#18586 for td64 and boolean mask case
654
642
655
643
@pytest .fixture (
656
- params = [NaT , np . timedelta64 ( "NaT " , "ns" ), np . datetime64 ( "NaT" , "ns" ) ]
644
+ params = ["m8[ns] " , "M8[ns]" , " datetime64[ns, UTC]" , "datetime64[ns, US/Central]" ]
657
645
)
658
- def val (self , request ):
646
+ def dtype (self , request ):
659
647
return request .param
660
648
661
649
@pytest .fixture
662
- def is_inplace (self , val ):
663
- # cast to object iff val is datetime64("NaT")
664
- return val is NaT or val .dtype .kind == "m"
665
-
666
- @pytest .fixture
667
- def expected (self , obj , val , is_inplace ):
668
- dtype = obj .dtype if is_inplace else object
669
- expected = Series ([val ] + list (obj [1 :]), dtype = dtype )
670
- return expected
671
-
672
- @pytest .fixture
673
- def key (self ):
674
- return 0
675
-
676
-
677
- class TestSetitemNADatetime64Dtype (SetitemCastingEquivalents ):
678
- # some nat-like values should be cast to datetime64 when inserting
679
- # into a datetime64 series. Others should coerce to object
680
- # and retain their dtypes.
681
-
682
- @pytest .fixture (params = [None , "UTC" , "US/Central" ])
683
- def obj (self , request ):
684
- tz = request .param
685
- dti = date_range ("2016-01-01" , periods = 3 , tz = tz )
686
- return Series (dti )
650
+ def obj (self , dtype ):
651
+ i8vals = date_range ("2016-01-01" , periods = 3 ).asi8
652
+ idx = Index (i8vals , dtype = dtype )
653
+ assert idx .dtype == dtype
654
+ return Series (idx )
687
655
688
656
@pytest .fixture (
689
- params = [NaT , np .timedelta64 ("NaT" , "ns" ), np .datetime64 ("NaT" , "ns" )]
657
+ params = [
658
+ None ,
659
+ np .nan ,
660
+ NaT ,
661
+ np .timedelta64 ("NaT" , "ns" ),
662
+ np .datetime64 ("NaT" , "ns" ),
663
+ ]
690
664
)
691
665
def val (self , request ):
692
666
return request .param
693
667
694
668
@pytest .fixture
695
669
def is_inplace (self , val , obj ):
696
- if obj ._values .tz is None :
697
- # cast to object iff val is timedelta64("NaT")
698
- return val is NaT or val .dtype .kind == "M"
699
-
700
- # otherwise we have to exclude tznaive dt64("NaT")
701
- return val is NaT
670
+ # td64 -> cast to object iff val is datetime64("NaT")
671
+ # dt64 -> cast to object iff val is timedelta64("NaT")
672
+ # dt64tz -> cast to object with anything _but_ NaT
673
+ return val is NaT or val is None or val is np .nan or obj .dtype == val .dtype
702
674
703
675
@pytest .fixture
704
676
def expected (self , obj , val , is_inplace ):
0 commit comments