Skip to content

CLN explicit float casts in tests #50733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,15 +1936,19 @@ def test_dataframe_blockwise_slicelike():
# GH#34367
arr = np.random.randint(0, 1000, (100, 10))
df1 = DataFrame(arr)
df2 = df1.copy()
# Explicit cast to float to avoid implicit cast when setting nan
df2 = df1.copy().astype({1: "float", 3: "float", 7: "float"})
df2.iloc[0, [1, 3, 7]] = np.nan

df3 = df1.copy()
# Explicit cast to float to avoid implicit cast when setting nan
df3 = df1.copy().astype({5: "float"})
df3.iloc[0, [5]] = np.nan

df4 = df1.copy()
# Explicit cast to float to avoid implicit cast when setting nan
df4 = df1.copy().astype({2: "float", 3: "float", 4: "float"})
df4.iloc[0, np.arange(2, 5)] = np.nan
df5 = df1.copy()
# Explicit cast to float to avoid implicit cast when setting nan
df5 = df1.copy().astype({4: "float", 5: "float", 6: "float"})
df5.iloc[0, np.arange(4, 7)] = np.nan

for left, right in [(df1, df2), (df2, df3), (df4, df5)]:
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,8 @@ def test_cummin(dtypes_for_minmax):
tm.assert_frame_equal(result, expected, check_exact=True)

# Test nan in some values
# Explicit cast to float to avoid implicit cast when setting nan
base_df = base_df.astype({"B": "float"})
base_df.loc[[0, 2, 4, 6], "B"] = np.nan
expected = DataFrame({"B": [np.nan, 4, np.nan, 2, np.nan, 3, np.nan, 1]})
result = base_df.groupby("A").cummin()
Expand Down Expand Up @@ -891,6 +893,8 @@ def test_cummax(dtypes_for_minmax):
tm.assert_frame_equal(result, expected)

# Test nan in some values
# Explicit cast to float to avoid implicit cast when setting nan
base_df = base_df.astype({"B": "float"})
base_df.loc[[0, 2, 4, 6], "B"] = np.nan
expected = DataFrame({"B": [np.nan, 4, np.nan, 4, np.nan, 3, np.nan, 3]})
result = base_df.groupby("A").cummax()
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def test_eng_float_formatter(self, float_frame):
)
def test_show_counts(self, row, columns, show_counts, result):

df = DataFrame(1, columns=range(10), index=range(10))
# Explicit cast to float to avoid implicit cast when setting nan
df = DataFrame(1, columns=range(10), index=range(10)).astype({1: "float"})
df.iloc[1, 1] = np.nan

with option_context(
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/resample/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_asfreq_fill_value(series, create_index):
expected = ser.reindex(new_index)
tm.assert_series_equal(result, expected)

frame = ser.to_frame("value")
# Explicit cast to float to avoid implicit cast when setting None
frame = ser.astype("float").to_frame("value")
frame.iloc[1] = None
result = frame.resample("1H").asfreq(fill_value=4.0)
new_index = create_index(frame.index[0], frame.index[-1], freq="1H")
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/reshape/merge/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def run_asserts(left, right, sort):

lc = list(map(chr, np.arange(ord("a"), ord("z") + 1)))
left = DataFrame(np.random.choice(lc, (5000, 2)), columns=["1st", "3rd"])
left.insert(1, "2nd", np.random.randint(0, 1000, len(left)))
# Explicit cast to float to avoid implicit cast when setting nan
left.insert(1, "2nd", np.random.randint(0, 1000, len(left)).astype("float"))

i = np.random.permutation(len(left))
right = left.iloc[i].copy()
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def test_closed_uneven():
def test_closed_min_max_minp(func, closed, expected):
# see gh-21704
ser = Series(data=np.arange(10), index=date_range("2000", periods=10))
# Explicit cast to float to avoid implicit cast when setting nan
ser = ser.astype("float")
ser[ser.index[-3:]] = np.nan
result = getattr(ser.rolling("3D", min_periods=2, closed=closed), func)()
expected = Series(expected, index=ser.index)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/window/test_timeseries_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ def test_ragged_max(self, ragged):
def test_freqs_ops(self, freq, op, result_data):
# GH 21096
index = date_range(start="2018-1-1 01:00:00", freq=f"1{freq}", periods=10)
s = Series(data=0, index=index)
# Explicit cast to float to avoid implicit cast when setting nan
s = Series(data=0, index=index, dtype="float")
s.iloc[1] = np.nan
s.iloc[-1] = 2
result = getattr(s.rolling(window=f"10{freq}"), op)()
Expand Down