Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Fixed Regressions
- Fixed regression in creating a period-dtype array from a read-only NumPy array of period objects. (:issue:`25403`)
- Fixed regression in :class:`Categorical`, where constructing it from a categorical ``Series`` and an explicit ``categories=`` that differed from that in the ``Series`` created an invalid object which could trigger segfaults. (:issue:`25318`)
- Fixed pip installing from source into an environment without NumPy (:issue:`25193`)
- Fixed regression in :meth:`DataFrame.replace` where large strings of numbers would be coerced into ``int64``, causing an ``OverflowError`` (:issue:`25616`)

.. _whatsnew_0242.enhancements:

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ def coerce_to_target_dtype(self, other):

try:
return self.astype(dtype)
except (ValueError, TypeError):
except (ValueError, TypeError, OverflowError):
pass

return self.astype(object)
Expand Down Expand Up @@ -3210,7 +3210,7 @@ def _putmask_smart(v, m, n):
nv = v.copy()
nv[m] = nn_at
return nv
except (ValueError, IndexError, TypeError):
except (ValueError, IndexError, TypeError, OverflowError):
pass

n = np.asarray(n)
Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/series/test_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,17 @@ def test_replace_mixed_types_with_string(self):
result = s.replace([2, '4'], np.nan)
expected = pd.Series([1, np.nan, 3, np.nan, 4, 5])
tm.assert_series_equal(expected, result)

def test_replace_with_no_overflowerror(self):
# GH 25616
# casts to object without Exception from OverflowError
s = pd.Series([0, 1, 2, 3, 4])
result = s.replace([3], ['100000000000000000000'])
expected = pd.Series([0, 1, 2, '100000000000000000000', 4])
tm.assert_series_equal(result, expected)

s = pd.Series([0, '100000000000000000000',
'100000000000000000001'])
result = s.replace(['100000000000000000000'], [1])
expected = pd.Series([0, 1, '100000000000000000001'])
tm.assert_series_equal(result, expected)