Skip to content

Commit e115956

Browse files
committed
Added test for float32 upcast in array_ops
1 parent b24df58 commit e115956

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ Conversion
752752
- Bug in :meth:`Series.astype` might modify read-only array inplace when casting to a string dtype (:issue:`57212`)
753753
- Bug in :meth:`Series.convert_dtypes` and :meth:`DataFrame.convert_dtypes` removing timezone information for objects with :class:`ArrowDtype` (:issue:`60237`)
754754
- Bug in :meth:`Series.reindex` not maintaining ``float32`` type when a ``reindex`` introduces a missing value (:issue:`45857`)
755+
- Bug in :meth:`_array_ops._maybe_prepare_scalar_for_op` not maintaining ``float32`` type when converting NumPy floating scalars (:issue:`61951`)
755756

756757
Strings
757758
^^^^^^^

pandas/tests/series/methods/test_convert_dtypes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,9 @@ def test_convert_dtype_pyarrow_timezone_preserve(self):
318318
result = ser.convert_dtypes(dtype_backend="pyarrow")
319319
expected = ser.copy()
320320
tm.assert_series_equal(result, expected)
321+
322+
def test_float32_series_addition_preserves_dtype(self):
323+
# GH#61951
324+
ser_a = pd.Series(np.zeros(1000000), dtype="float32") + np.float32(1)
325+
ser_b = pd.Series(np.zeros(1000001), dtype="float32") + np.float32(1)
326+
assert all(dtype == np.float32 for dtype in (ser_a.dtype, ser_b.dtype))

0 commit comments

Comments
 (0)