Skip to content

Commit 1e4e624

Browse files
authored
CLN avoid more test warnings (#50621)
1 parent 01cbaea commit 1e4e624

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pandas/tests/frame/methods/test_describe.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,9 @@ def test_ea_with_na(self, any_numeric_ea_dtype):
388388
# GH#48778
389389

390390
df = DataFrame({"a": [1, pd.NA, pd.NA], "b": pd.NA}, dtype=any_numeric_ea_dtype)
391-
result = df.describe()
391+
# Warning from numpy for taking std of single element
392+
with tm.assert_produces_warning(RuntimeWarning, check_stacklevel=False):
393+
result = df.describe()
392394
expected = DataFrame(
393395
{"a": [1.0, 1.0, pd.NA] + [1.0] * 5, "b": [0.0] + [pd.NA] * 7},
394396
index=["count", "mean", "std", "min", "25%", "50%", "75%", "max"],

pandas/tests/frame/methods/test_shift.py

+14
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,13 @@ def test_shift_axis1_multiple_blocks(self, using_array_manager):
397397
result = df3.shift(2, axis=1)
398398

399399
expected = df3.take([-1, -1, 0, 1, 2], axis=1)
400+
# Explicit cast to float to avoid implicit cast when setting nan.
401+
# Column names aren't unique, so directly calling `expected.astype` won't work.
402+
expected = expected.pipe(
403+
lambda df: df.set_axis(range(df.shape[1]), axis=1)
404+
.astype({0: "float", 1: "float"})
405+
.set_axis(df.columns, axis=1)
406+
)
400407
expected.iloc[:, :2] = np.nan
401408
expected.columns = df3.columns
402409

@@ -410,6 +417,13 @@ def test_shift_axis1_multiple_blocks(self, using_array_manager):
410417
result = df3.shift(-2, axis=1)
411418

412419
expected = df3.take([2, 3, 4, -1, -1], axis=1)
420+
# Explicit cast to float to avoid implicit cast when setting nan.
421+
# Column names aren't unique, so directly calling `expected.astype` won't work.
422+
expected = expected.pipe(
423+
lambda df: df.set_axis(range(df.shape[1]), axis=1)
424+
.astype({3: "float", 4: "float"})
425+
.set_axis(df.columns, axis=1)
426+
)
413427
expected.iloc[:, -2:] = np.nan
414428
expected.columns = df3.columns
415429

0 commit comments

Comments
 (0)