From b288d19d031ae699ecd480fbac70595472aa5295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Konefa=C5=82?= Date: Wed, 22 Nov 2017 20:28:10 +0100 Subject: [PATCH 1/4] BUG: fillna maximum recursion depth exceeded in cmp (GH18159). --- doc/source/whatsnew/v0.21.1.txt | 2 ++ pandas/core/internals.py | 5 +++-- pandas/tests/internals/test_internals.py | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.1.txt b/doc/source/whatsnew/v0.21.1.txt index a9608594be547..aaddc61f8aeb8 100644 --- a/doc/source/whatsnew/v0.21.1.txt +++ b/doc/source/whatsnew/v0.21.1.txt @@ -56,6 +56,8 @@ Documentation Changes Bug Fixes ~~~~~~~~~ +- Bug in :meth:`fillna` where maximum recursion depth gets exceeded in comparison (:issue:`18159`). + Conversion ^^^^^^^^^^ diff --git a/pandas/core/internals.py b/pandas/core/internals.py index e5db5679c43f6..6b7ebe12b9724 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1847,8 +1847,9 @@ def _can_hold_element(self, element): if tipo is not None: return (issubclass(tipo.type, (np.floating, np.integer)) and not issubclass(tipo.type, (np.datetime64, np.timedelta64))) - return (isinstance(element, (float, int, np.floating, np.int_)) and - not isinstance(element, (bool, np.bool_, datetime, timedelta, + return ( + isinstance(element, (float, int, np.floating, np.int_, compat.long)) + and not isinstance(element, (bool, np.bool_, datetime, timedelta, np.datetime64, np.timedelta64))) def to_native_types(self, slicer=None, na_rep='', float_format=None, diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index a22d0174947e1..ac78def824b3e 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -1222,6 +1222,7 @@ class TestCanHoldElement(object): @pytest.mark.parametrize('value, dtype', [ (1, 'i8'), (1.0, 'f8'), + (2**63, 'f8'), (1j, 'complex128'), (True, 'bool'), (np.timedelta64(20, 'ns'), ' Date: Sun, 3 Dec 2017 10:18:06 +0100 Subject: [PATCH 2/4] Applied requested changes --- doc/source/whatsnew/v0.21.1.txt | 2 +- pandas/core/internals.py | 2 +- pandas/tests/internals/test_internals.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.1.txt b/doc/source/whatsnew/v0.21.1.txt index aaddc61f8aeb8..149a9931c91a0 100644 --- a/doc/source/whatsnew/v0.21.1.txt +++ b/doc/source/whatsnew/v0.21.1.txt @@ -56,7 +56,7 @@ Documentation Changes Bug Fixes ~~~~~~~~~ -- Bug in :meth:`fillna` where maximum recursion depth gets exceeded in comparison (:issue:`18159`). +- Bug in :meth:`Series.fillna` which was raising RuntimeError when got large integer (:issue:`18159`). Conversion diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 6b7ebe12b9724..a215c5a0b6b13 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1898,7 +1898,7 @@ def _can_hold_element(self, element): return issubclass(tipo.type, (np.floating, np.integer, np.complexfloating)) return (isinstance(element, - (float, int, complex, np.float_, np.int_)) and + (float, int, complex, np.float_, np.int_, compat.long)) and not isinstance(element, (bool, np.bool_))) def should_store(self, value): diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index ac78def824b3e..08f769e02e267 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -1224,6 +1224,7 @@ class TestCanHoldElement(object): (1.0, 'f8'), (2**63, 'f8'), (1j, 'complex128'), + (2**63, 'complex128'), (True, 'bool'), (np.timedelta64(20, 'ns'), ' Date: Sun, 3 Dec 2017 22:21:01 +0100 Subject: [PATCH 3/4] Moved change log to conversions section --- doc/source/whatsnew/v0.21.1.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.1.txt b/doc/source/whatsnew/v0.21.1.txt index 149a9931c91a0..73962efad61e7 100644 --- a/doc/source/whatsnew/v0.21.1.txt +++ b/doc/source/whatsnew/v0.21.1.txt @@ -56,7 +56,7 @@ Documentation Changes Bug Fixes ~~~~~~~~~ -- Bug in :meth:`Series.fillna` which was raising RuntimeError when got large integer (:issue:`18159`). +- Conversion @@ -67,6 +67,7 @@ Conversion - Bug in :meth:`IntervalIndex.copy` when copying and ``IntervalIndex`` with non-default ``closed`` (:issue:`18339`) - Bug in :func:`DataFrame.to_dict` where columns of datetime that are tz-aware were not converted to required arrays when used with ``orient='records'``, raising``TypeError` (:issue:`18372`) - Bug in :class:`DateTimeIndex` and :meth:`date_range` where mismatching tz-aware ``start`` and ``end`` timezones would not raise an err if ``end.tzinfo`` is None (:issue:`18431`) +- Bug in :meth:`Series.fillna` which raised when passed a long integer on Python 2 (:issue:`18159`). - Indexing From 03b2f6b1e7d121b7b34bb998914c684357c0f98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Konefa=C5=82?= Date: Fri, 8 Dec 2017 17:57:43 +0100 Subject: [PATCH 4/4] Lint fixes --- pandas/core/internals.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/core/internals.py b/pandas/core/internals.py index a215c5a0b6b13..4169a001655cb 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -1848,7 +1848,8 @@ def _can_hold_element(self, element): return (issubclass(tipo.type, (np.floating, np.integer)) and not issubclass(tipo.type, (np.datetime64, np.timedelta64))) return ( - isinstance(element, (float, int, np.floating, np.int_, compat.long)) + isinstance( + element, (float, int, np.floating, np.int_, compat.long)) and not isinstance(element, (bool, np.bool_, datetime, timedelta, np.datetime64, np.timedelta64))) @@ -1897,9 +1898,11 @@ def _can_hold_element(self, element): if tipo is not None: return issubclass(tipo.type, (np.floating, np.integer, np.complexfloating)) - return (isinstance(element, - (float, int, complex, np.float_, np.int_, compat.long)) and - not isinstance(element, (bool, np.bool_))) + return ( + isinstance( + element, + (float, int, complex, np.float_, np.int_, compat.long)) + and not isinstance(element, (bool, np.bool_))) def should_store(self, value): return issubclass(value.dtype.type, np.complexfloating)