From 30e548c4fc7c21d2b752c7997aba1058bb02bdeb Mon Sep 17 00:00:00 2001 From: Matthew Willian Date: Mon, 11 Jul 2016 18:50:57 -0400 Subject: [PATCH 1/5] remove flags --- pandas/core/nanops.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index f390e3f04a6c3..7c13c23f731da 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -454,8 +454,7 @@ def nanargmax(values, axis=None, skipna=True): """ Returns -1 in the NA case """ - values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf', - isfinite=True) + values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='-inf') result = values.argmax(axis) result = _maybe_arg_null_out(result, axis, mask, skipna) return result @@ -465,8 +464,7 @@ def nanargmin(values, axis=None, skipna=True): """ Returns -1 in the NA case """ - values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf', - isfinite=True) + values, mask, dtype, _ = _get_values(values, skipna, fill_value_typ='+inf') result = values.argmin(axis) result = _maybe_arg_null_out(result, axis, mask, skipna) return result From 82b26c33e4e07131aefacc125e1ffdf4715b4cc0 Mon Sep 17 00:00:00 2001 From: Matthew Willian Date: Mon, 11 Jul 2016 19:41:00 -0400 Subject: [PATCH 2/5] add tests --- pandas/tests/test_nanops.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index 904bedde03312..0c85ec9638ca9 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -41,6 +41,7 @@ def setUp(self): self.arr_inf = self.arr_float * np.inf self.arr_float_inf = np.vstack([self.arr_float, self.arr_inf]) + self.arr_float_neg_inf = -1 * self.arr_float_inf self.arr_float1_inf = np.vstack([self.arr_float1, self.arr_inf]) self.arr_inf_float1 = np.vstack([self.arr_inf, self.arr_float1]) self.arr_inf_inf = np.vstack([self.arr_inf, self.arr_inf]) @@ -234,7 +235,7 @@ def check_fun(self, testfunc, targfunc, testar, targar=None, def check_funs(self, testfunc, targfunc, allow_complex=True, allow_all_nan=True, allow_str=True, allow_date=True, - allow_tdelta=True, allow_obj=True, **kwargs): + allow_tdelta=True, allow_obj=True, allow_inf=True, **kwargs): self.check_fun(testfunc, targfunc, 'arr_float', **kwargs) self.check_fun(testfunc, targfunc, 'arr_float_nan', 'arr_float', **kwargs) @@ -287,6 +288,10 @@ def check_funs(self, testfunc, targfunc, allow_complex=True, allow_complex=allow_complex) self.check_fun(testfunc, targfunc, 'arr_obj', **kwargs) + if allow_inf: + self.check_fun(testfunc, targfunc, 'arr_float_inf', **kwargs) + self.check_fun(testfunc, targfunc, 'arr_float_neg_inf', **kwargs) + def check_funs_ddof(self, testfunc, targfunc, @@ -295,7 +300,7 @@ def check_funs_ddof(self, allow_str=True, allow_date=False, allow_tdelta=False, - allow_obj=True, ): + allow_obj=True): for ddof in range(3): try: self.check_funs(testfunc, targfunc, allow_complex, From be65aa72c3ce06af583031205300e743dcbf53f0 Mon Sep 17 00:00:00 2001 From: Matthew Willian Date: Mon, 11 Jul 2016 19:46:20 -0400 Subject: [PATCH 3/5] add to what's new --- doc/source/whatsnew/v0.18.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index 7418cd0e6baa3..55c1ea2460ba0 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -1290,3 +1290,4 @@ Bug Fixes - Bug when specifying a UTC ``DatetimeIndex`` by setting ``utc=True`` in ``.to_datetime`` (:issue:`11934`) - Bug when increasing the buffer size of CSV reader in ``read_csv`` (:issue:`12494`) - Bug when setting columns of a ``DataFrame`` with duplicate column names (:issue:`12344`) +- Bug when calling Series.argmax with infinite values (:issue: `13595`) From c2c5ac6ea7a8b97e8ef16134787c36e95f541260 Mon Sep 17 00:00:00 2001 From: Matthew Willian Date: Mon, 11 Jul 2016 20:16:52 -0400 Subject: [PATCH 4/5] move whatsnew + add test --- doc/source/whatsnew/v0.18.0.txt | 1 - doc/source/whatsnew/v0.19.0.txt | 2 ++ pandas/tests/series/test_analytics.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.18.0.txt b/doc/source/whatsnew/v0.18.0.txt index 55c1ea2460ba0..7418cd0e6baa3 100644 --- a/doc/source/whatsnew/v0.18.0.txt +++ b/doc/source/whatsnew/v0.18.0.txt @@ -1290,4 +1290,3 @@ Bug Fixes - Bug when specifying a UTC ``DatetimeIndex`` by setting ``utc=True`` in ``.to_datetime`` (:issue:`11934`) - Bug when increasing the buffer size of CSV reader in ``read_csv`` (:issue:`12494`) - Bug when setting columns of a ``DataFrame`` with duplicate column names (:issue:`12344`) -- Bug when calling Series.argmax with infinite values (:issue: `13595`) diff --git a/doc/source/whatsnew/v0.19.0.txt b/doc/source/whatsnew/v0.19.0.txt index 4cc16aac15f8b..0ba58ab2181c7 100644 --- a/doc/source/whatsnew/v0.19.0.txt +++ b/doc/source/whatsnew/v0.19.0.txt @@ -549,3 +549,5 @@ Bug Fixes - Bug in ``groupby`` with ``as_index=False`` returns all NaN's when grouping on multiple columns including a categorical one (:issue:`13204`) - Bug where ``pd.read_gbq()`` could throw ``ImportError: No module named discovery`` as a result of a naming conflict with another python package called apiclient (:issue:`13454`) + +- Bug when calling Series.argmax with infinite values (:issue: `13595`) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d9e2d8096c8d7..03c34b90c7a6c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -1282,6 +1282,14 @@ def test_idxmax(self): result = s.idxmin() self.assertEqual(result, 1.1) + # Infinite values + # GH 13595 + s = pd.Series([1, 2, np.inf]) + result = s.idxmax() + self.assertEqual(result, 2) + result = s.idxmax(skipna=False) + self.assertEqual(result, 2) + def test_numpy_argmax(self): # argmax is aliased to idxmax From 790275edfc196464f53cf05ae64064d4538997fb Mon Sep 17 00:00:00 2001 From: Matthew Willian Date: Tue, 12 Jul 2016 10:35:03 -0400 Subject: [PATCH 5/5] fix formatting --- doc/source/whatsnew/v0.19.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.19.0.txt b/doc/source/whatsnew/v0.19.0.txt index 0ba58ab2181c7..022d8545ca658 100644 --- a/doc/source/whatsnew/v0.19.0.txt +++ b/doc/source/whatsnew/v0.19.0.txt @@ -550,4 +550,4 @@ Bug Fixes - Bug where ``pd.read_gbq()`` could throw ``ImportError: No module named discovery`` as a result of a naming conflict with another python package called apiclient (:issue:`13454`) -- Bug when calling Series.argmax with infinite values (:issue: `13595`) +- Bug when calling ``Series.argmax`` with infinite values (:issue:`13595`)