Skip to content

Commit 3917ab8

Browse files
committed
added tests
1 parent 78c8d83 commit 3917ab8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/core/frame.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,10 @@ def check_int_infer_dtype(dtypes):
42814281
# "Type[signedinteger[Any]]"; expected "Type[signedinteger[Any]]"
42824282
converted_dtypes.append(np.int64) # type: ignore[arg-type]
42834283
elif dtype == "float":
4284-
converted_dtypes.extend([np.float64, np.float32])
4284+
# GH#42452 : np.dtype("float") coerces to np.float64 from Numpy 1.20
4285+
converted_dtypes.extend(
4286+
[np.float64, np.float32, np.float16]
4287+
) # type: ignore[list-item]
42854288
else:
42864289
# error: Argument 1 to "append" of "list" has incompatible type
42874290
# "Union[dtype[Any], ExtensionDtype]"; expected

pandas/tests/window/test_ewm.py

+11
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,14 @@ def test_ewma_times_adjust_false_raises():
181181
Series(range(1)).ewm(
182182
0.1, adjust=False, times=date_range("2000", freq="D", periods=1)
183183
)
184+
185+
186+
@pytest.mark.parametrize("func", ["mean", "std", "var"])
187+
@pytest.mark.parametrize("dtype", [np.float32, np.float16, np.float64, float, "float"])
188+
def test_float_dtype_ewma(dtype, func):
189+
# GH#42452
190+
df = DataFrame(np.random.rand(20, 3), dtype=dtype)
191+
e = df.ewm(alpha=0.5, axis=1)
192+
result = getattr(e, func)().shape
193+
expected = (20, 3)
194+
assert result == expected, f"Shape of ewm {func} must match dataframe"

0 commit comments

Comments
 (0)