Skip to content

Commit 472c09a

Browse files
committed
wip
1 parent 11e1ee8 commit 472c09a

File tree

1 file changed

+0
-105
lines changed

1 file changed

+0
-105
lines changed

pandas/tests/frame/indexing/test_where.py

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -512,28 +512,10 @@ def test_where_axis_with_upcast(self):
512512
result = df.where(mask, ser, axis="index")
513513
tm.assert_frame_equal(result, expected)
514514

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-
521515
expected = DataFrame([[0, np.nan], [0, np.nan]])
522516
result = df.where(mask, ser, axis="columns")
523517
tm.assert_frame_equal(result, expected)
524518

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-
537519
def test_where_axis_multiple_dtypes(self):
538520
# Multiple dtypes (=> multiple Blocks)
539521
df = pd.concat(
@@ -583,16 +565,6 @@ def test_where_axis_multiple_dtypes(self):
583565
tm.assert_frame_equal(result, expected)
584566
result = df.where(mask, d1, axis="index")
585567
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)
596568

597569
d2 = df.copy().drop(1, axis=1)
598570
expected = df.copy()
@@ -732,19 +704,6 @@ def test_where_interval_noop(self):
732704
res = ser.where(ser.notna())
733705
tm.assert_series_equal(res, ser)
734706

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-
748707
@pytest.mark.parametrize(
749708
"dtype",
750709
[
@@ -773,14 +732,6 @@ def test_where_datetimelike_noop(self, dtype):
773732

774733
res4 = df.mask(mask2, "foo")
775734
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))
784735

785736

786737
def test_where_int_downcasting_deprecated():
@@ -934,12 +885,6 @@ def test_where_period_invalid_na(frame_or_series, as_cat, request):
934885
result = obj.mask(mask, tdnat)
935886
tm.assert_equal(result, expected)
936887

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-
943888

944889
def test_where_nullable_invalid_na(frame_or_series, any_numeric_ea_dtype):
945890
# GH#44697
@@ -981,56 +926,6 @@ def test_where_downcast_to_td64():
981926
tm.assert_series_equal(res2, expected2)
982927

983928

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-
1034929
def test_where_producing_ea_cond_for_np_dtype():
1035930
# GH#44014
1036931
df = DataFrame({"a": Series([1, pd.NA, 2], dtype="Int64"), "b": [1, 2, 3]})

0 commit comments

Comments
 (0)