Skip to content

Commit 08b3556

Browse files
author
MarcoGorelli
committed
a few more
1 parent 23d38dc commit 08b3556

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

pandas/tests/frame/indexing/test_setitem.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,7 @@ def test_setitem_other_callable(self):
987987
def inc(x):
988988
return x + 1
989989

990-
# Set dtype object straight away to avoid upcast when setting
991-
# inc below
990+
# Set dtype object straight away to avoid upcast when setting inc below
992991
df = DataFrame([[-1, 1], [1, -1]], dtype=object)
993992
df[df > 0] = inc
994993

pandas/tests/frame/methods/test_map.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def test_map_na_ignore(float_frame):
111111
strlen_frame_na_ignore = float_frame_with_na.map(
112112
lambda x: len(str(x)), na_action="ignore"
113113
)
114-
strlen_frame_with_na = strlen_frame.copy()
114+
# Set float64 type to avoid upcast when setting NA below
115+
strlen_frame_with_na = strlen_frame.copy().astype("float64")
115116
strlen_frame_with_na[mask] = pd.NA
116117
tm.assert_frame_equal(strlen_frame_na_ignore, strlen_frame_with_na)
117118

pandas/tests/groupby/test_counting.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,10 @@ def test_count_object():
327327

328328
def test_count_cross_type():
329329
# GH8169
330+
# Set float64 dtype to avoid upcast when setting nan below
330331
vals = np.hstack(
331332
(np.random.randint(0, 5, (100, 2)), np.random.randint(0, 2, (100, 2)))
332-
)
333+
).astype("float64")
333334

334335
df = DataFrame(vals, columns=["a", "b", "c", "d"])
335336
df[df == 2] = np.nan

pandas/tests/groupby/test_filters.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ def test_filter_and_transform_with_non_unique_int_index():
363363
tm.assert_frame_equal(actual, expected)
364364

365365
actual = grouped_df.filter(lambda x: len(x) > 1, dropna=False)
366-
expected = df.copy()
366+
# Cast to avoid upcast when setting nan below
367+
expected = df.copy().astype("float64")
367368
expected.iloc[[0, 3, 5, 6]] = np.nan
368369
tm.assert_frame_equal(actual, expected)
369370

@@ -405,7 +406,8 @@ def test_filter_and_transform_with_multiple_non_unique_int_index():
405406
tm.assert_frame_equal(actual, expected)
406407

407408
actual = grouped_df.filter(lambda x: len(x) > 1, dropna=False)
408-
expected = df.copy()
409+
# Cast to avoid upcast when setting nan below
410+
expected = df.copy().astype("float64")
409411
expected.iloc[[0, 3, 5, 6]] = np.nan
410412
tm.assert_frame_equal(actual, expected)
411413

@@ -447,7 +449,8 @@ def test_filter_and_transform_with_non_unique_float_index():
447449
tm.assert_frame_equal(actual, expected)
448450

449451
actual = grouped_df.filter(lambda x: len(x) > 1, dropna=False)
450-
expected = df.copy()
452+
# Cast to avoid upcast when setting nan below
453+
expected = df.copy().astype("float64")
451454
expected.iloc[[0, 3, 5, 6]] = np.nan
452455
tm.assert_frame_equal(actual, expected)
453456

@@ -492,7 +495,8 @@ def test_filter_and_transform_with_non_unique_timestamp_index():
492495
tm.assert_frame_equal(actual, expected)
493496

494497
actual = grouped_df.filter(lambda x: len(x) > 1, dropna=False)
495-
expected = df.copy()
498+
# Cast to avoid upcast when setting nan below
499+
expected = df.copy().astype("float64")
496500
expected.iloc[[0, 3, 5, 6]] = np.nan
497501
tm.assert_frame_equal(actual, expected)
498502

@@ -534,7 +538,8 @@ def test_filter_and_transform_with_non_unique_string_index():
534538
tm.assert_frame_equal(actual, expected)
535539

536540
actual = grouped_df.filter(lambda x: len(x) > 1, dropna=False)
537-
expected = df.copy()
541+
# Cast to avoid upcast when setting nan below
542+
expected = df.copy().astype("float64")
538543
expected.iloc[[0, 3, 5, 6]] = np.nan
539544
tm.assert_frame_equal(actual, expected)
540545

pandas/tests/groupby/test_groupby.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def f_1(grp):
166166
return grp.iloc[0]
167167

168168
result = df.groupby("A").apply(f_1)[["B"]]
169-
e = expected.copy()
169+
# Cast to avoid upcast when setting nan below
170+
e = expected.copy().astype("float64")
170171
e.loc["Tiger"] = np.nan
171172
tm.assert_frame_equal(result, e)
172173

0 commit comments

Comments
 (0)