Skip to content

Commit fe7e8c8

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

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
@@ -2204,7 +2204,11 @@ def test_df_mul_series_fill_value():
22042204
df.iat[i + 1, i] = np.nan
22052205
df.iat[i + 4, i] = np.nan
22062206

2207-
df_result = df[["A", "B", "C", "D"]].mul(df["E"], axis=0, fill_value=5)
2208-
df_expected = df[["A", "B", "C", "D"]].mul(df["E"].fillna(5), axis=0)
2207+
df_a = df.iloc[:, :-1]
2208+
df_b = df.iloc[:, -1]
2209+
nan_mask = df_a.isna().astype(int).mul(df_b.isna().astype(int), axis=0).astype(bool)
2210+
2211+
df_result = df_a.mul(df_b, axis=0, fill_value=5)
2212+
df_expected = (df_a.fillna(5).mul(df_b.fillna(5), axis=0)).mask(nan_mask, np.nan)
22092213

22102214
tm.assert_frame_equal(df_result, df_expected)

0 commit comments

Comments
 (0)