Skip to content

Commit

Permalink
BUG: Fix error in replace with strings that are large numbers (#25616) (
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialQualia authored and jorisvandenbossche committed Mar 12, 2019
1 parent a8fad16 commit 12fd316
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Fixed Regressions
- 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 regression in :func:`to_timedelta` losing precision when converting floating data to ``Timedelta`` data (:issue:`25077`).
- 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`)
- Fixed regression in :func:`factorize` when passing a custom ``na_sentinel`` value with ``sort=True`` (:issue:`25409`).
- Fixed regression in :meth:`DataFrame.to_csv` writing duplicate line endings with gzip compress (:issue:`25311`)

Expand Down Expand Up @@ -90,6 +91,7 @@ A total of 25 people contributed patches to this release. People with a "+" by t
* Joris Van den Bossche
* Josh
* Justin Zheng
* Kendall Masse
* Matthew Roeschke
* Max Bolingbroke +
* rbenes +
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)

0 comments on commit 12fd316

Please sign in to comment.