Skip to content

Commit f303a04

Browse files
committed
Updated test case to account for results of mul being NaN if both inputs are NaN
1 parent a9c8d85 commit f303a04

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/tests/frame/test_arithmetic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,11 @@ def test_df_mul_series_fill_value():
22112211
df.iat[i + 1, i] = np.nan
22122212
df.iat[i + 4, i] = np.nan
22132213

2214-
df_result = df[["A", "B", "C", "D"]].mul(df["E"], axis=0, fill_value=5)
2215-
df_expected = df[["A", "B", "C", "D"]].mul(df["E"].fillna(5), axis=0)
2214+
df_a = df.iloc[:, :-1]
2215+
df_b = df.iloc[:, -1]
2216+
nan_mask = df_a.isna().astype(int).mul(df_b.isna().astype(int), axis=0).astype(bool)
2217+
2218+
df_result = df_a.mul(df_b, axis=0, fill_value=5)
2219+
df_expected = (df_a.fillna(5).mul(df_b.fillna(5), axis=0)).mask(nan_mask, np.nan)
22162220

22172221
tm.assert_frame_equal(df_result, df_expected)

0 commit comments

Comments
 (0)