@@ -512,28 +512,10 @@ def test_where_axis_with_upcast(self):
512
512
result = df .where (mask , ser , axis = "index" )
513
513
tm .assert_frame_equal (result , expected )
514
514
515
- result = df .copy ()
516
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
517
- return_value = result .where (mask , ser , axis = "index" , inplace = True )
518
- assert return_value is None
519
- tm .assert_frame_equal (result , expected )
520
-
521
515
expected = DataFrame ([[0 , np .nan ], [0 , np .nan ]])
522
516
result = df .where (mask , ser , axis = "columns" )
523
517
tm .assert_frame_equal (result , expected )
524
518
525
- expected = DataFrame (
526
- {
527
- 0 : np .array ([0 , 0 ], dtype = "int64" ),
528
- 1 : np .array ([np .nan , np .nan ], dtype = "float64" ),
529
- }
530
- )
531
- result = df .copy ()
532
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
533
- return_value = result .where (mask , ser , axis = "columns" , inplace = True )
534
- assert return_value is None
535
- tm .assert_frame_equal (result , expected )
536
-
537
519
def test_where_axis_multiple_dtypes (self ):
538
520
# Multiple dtypes (=> multiple Blocks)
539
521
df = pd .concat (
@@ -583,16 +565,6 @@ def test_where_axis_multiple_dtypes(self):
583
565
tm .assert_frame_equal (result , expected )
584
566
result = df .where (mask , d1 , axis = "index" )
585
567
tm .assert_frame_equal (result , expected )
586
- result = df .copy ()
587
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
588
- return_value = result .where (mask , d1 , inplace = True )
589
- assert return_value is None
590
- tm .assert_frame_equal (result , expected )
591
- result = df .copy ()
592
- with tm .assert_produces_warning (FutureWarning , match = "incompatible dtype" ):
593
- return_value = result .where (mask , d1 , inplace = True , axis = "index" )
594
- assert return_value is None
595
- tm .assert_frame_equal (result , expected )
596
568
597
569
d2 = df .copy ().drop (1 , axis = 1 )
598
570
expected = df .copy ()
@@ -732,19 +704,6 @@ def test_where_interval_noop(self):
732
704
res = ser .where (ser .notna ())
733
705
tm .assert_series_equal (res , ser )
734
706
735
- def test_where_interval_fullop_downcast (self , frame_or_series ):
736
- # GH#45768
737
- obj = frame_or_series ([pd .Interval (0 , 0 )] * 2 )
738
- other = frame_or_series ([1.0 , 2.0 ], dtype = object )
739
- res = obj .where (~ obj .notna (), other )
740
- tm .assert_equal (res , other )
741
-
742
- with tm .assert_produces_warning (
743
- FutureWarning , match = "Setting an item of incompatible dtype"
744
- ):
745
- obj .mask (obj .notna (), other , inplace = True )
746
- tm .assert_equal (obj , other .astype (object ))
747
-
748
707
@pytest .mark .parametrize (
749
708
"dtype" ,
750
709
[
@@ -773,14 +732,6 @@ def test_where_datetimelike_noop(self, dtype):
773
732
774
733
res4 = df .mask (mask2 , "foo" )
775
734
tm .assert_frame_equal (res4 , df )
776
- expected = DataFrame (4 , index = df .index , columns = df .columns )
777
-
778
- # unlike where, Block.putmask does not downcast
779
- with tm .assert_produces_warning (
780
- FutureWarning , match = "Setting an item of incompatible dtype"
781
- ):
782
- df .mask (~ mask2 , 4 , inplace = True )
783
- tm .assert_frame_equal (df , expected .astype (object ))
784
735
785
736
786
737
def test_where_int_downcasting_deprecated ():
@@ -934,12 +885,6 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request):
934
885
result = obj .mask (mask , tdnat )
935
886
tm .assert_equal (result , expected )
936
887
937
- with tm .assert_produces_warning (
938
- FutureWarning , match = "Setting an item of incompatible dtype"
939
- ):
940
- obj .mask (mask , tdnat , inplace = True )
941
- tm .assert_equal (obj , expected )
942
-
943
888
944
889
def test_where_nullable_invalid_na (frame_or_series , any_numeric_ea_dtype ):
945
890
# GH#44697
@@ -981,56 +926,6 @@ def test_where_downcast_to_td64():
981
926
tm .assert_series_equal (res2 , expected2 )
982
927
983
928
984
- def _check_where_equivalences (df , mask , other , expected ):
985
- # similar to tests.series.indexing.test_setitem.SetitemCastingEquivalences
986
- # but with DataFrame in mind and less fleshed-out
987
- res = df .where (mask , other )
988
- tm .assert_frame_equal (res , expected )
989
-
990
- res = df .mask (~ mask , other )
991
- tm .assert_frame_equal (res , expected )
992
-
993
- # Note: frame.mask(~mask, other, inplace=True) takes some more work bc
994
- # Block.putmask does *not* downcast. The change to 'expected' here
995
- # is specific to the cases in test_where_dt64_2d.
996
- df = df .copy ()
997
- df .mask (~ mask , other , inplace = True )
998
- if not mask .all ():
999
- # with mask.all(), Block.putmask is a no-op, so does not downcast
1000
- expected = expected .copy ()
1001
- expected ["A" ] = expected ["A" ].astype (object )
1002
- tm .assert_frame_equal (df , expected )
1003
-
1004
-
1005
- def test_where_dt64_2d ():
1006
- dti = date_range ("2016-01-01" , periods = 6 )
1007
- dta = dti ._data .reshape (3 , 2 )
1008
- other = dta - dta [0 , 0 ]
1009
-
1010
- df = DataFrame (dta , columns = ["A" , "B" ])
1011
-
1012
- mask = np .asarray (df .isna ()).copy ()
1013
- mask [:, 1 ] = True
1014
-
1015
- # setting part of one column, none of the other
1016
- mask [1 , 0 ] = True
1017
- expected = DataFrame (
1018
- {
1019
- "A" : np .array ([other [0 , 0 ], dta [1 , 0 ], other [2 , 0 ]], dtype = object ),
1020
- "B" : dta [:, 1 ],
1021
- }
1022
- )
1023
- with tm .assert_produces_warning (
1024
- FutureWarning , match = "Setting an item of incompatible dtype"
1025
- ):
1026
- _check_where_equivalences (df , mask , other , expected )
1027
-
1028
- # setting nothing in either column
1029
- mask [:] = True
1030
- expected = df
1031
- _check_where_equivalences (df , mask , other , expected )
1032
-
1033
-
1034
929
def test_where_producing_ea_cond_for_np_dtype ():
1035
930
# GH#44014
1036
931
df = DataFrame ({"a" : Series ([1 , pd .NA , 2 ], dtype = "Int64" ), "b" : [1 , 2 , 3 ]})
0 commit comments