From c66af8e9ad15476450ba56a050ee7dc0a5fcb364 Mon Sep 17 00:00:00 2001 From: Con Date: Wed, 24 May 2023 18:09:02 -0400 Subject: [PATCH 1/4] TST: adds test for Series and argwhere interaction --- pandas/tests/series/test_npfuncs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/series/test_npfuncs.py b/pandas/tests/series/test_npfuncs.py index a0b672fffa84a..8b071954bf2e0 100644 --- a/pandas/tests/series/test_npfuncs.py +++ b/pandas/tests/series/test_npfuncs.py @@ -3,8 +3,10 @@ """ import numpy as np +import pytest from pandas import Series +import pandas._testing as tm class TestPtp: @@ -19,3 +21,15 @@ def test_ptp(self): def test_numpy_unique(datetime_series): # it works! np.unique(datetime_series) + + +@pytest.mark.parametrize("index", [["a", "b", "c", "d", "e"], None]) +def test_numpy_argwhere(index): + # GH#35331 + + s = Series(range(5), index=index) + + result = np.argwhere(s > 2) + expected = np.array([[3], [4]]) + + tm.assert_numpy_array_equal(result, expected) From a411bbf3be355e119125aeb29198982237d796b3 Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 25 May 2023 10:08:24 -0400 Subject: [PATCH 2/4] Specify dtype for Win --- pandas/tests/series/test_npfuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_npfuncs.py b/pandas/tests/series/test_npfuncs.py index 8b071954bf2e0..845507bbb2685 100644 --- a/pandas/tests/series/test_npfuncs.py +++ b/pandas/tests/series/test_npfuncs.py @@ -30,6 +30,6 @@ def test_numpy_argwhere(index): s = Series(range(5), index=index) result = np.argwhere(s > 2) - expected = np.array([[3], [4]]) + expected = np.array([[3], [4]], dtype=np.int64) tm.assert_numpy_array_equal(result, expected) From c7c0db3ec7942c560c461ac1ca4fef71035c031f Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 25 May 2023 11:45:11 -0400 Subject: [PATCH 3/4] fix missing dtype --- pandas/tests/series/test_npfuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_npfuncs.py b/pandas/tests/series/test_npfuncs.py index 845507bbb2685..8fb73dc351b4c 100644 --- a/pandas/tests/series/test_npfuncs.py +++ b/pandas/tests/series/test_npfuncs.py @@ -27,7 +27,7 @@ def test_numpy_unique(datetime_series): def test_numpy_argwhere(index): # GH#35331 - s = Series(range(5), index=index) + s = Series(range(5), index=index, dtype=np.int64) result = np.argwhere(s > 2) expected = np.array([[3], [4]], dtype=np.int64) From a9a90bddaddef28e089adea28aa85d59d6dc111c Mon Sep 17 00:00:00 2001 From: Con Date: Thu, 25 May 2023 14:35:49 -0400 Subject: [PATCH 4/4] fix linux 32bit int --- pandas/tests/series/test_npfuncs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_npfuncs.py b/pandas/tests/series/test_npfuncs.py index 8fb73dc351b4c..6a575ab85943a 100644 --- a/pandas/tests/series/test_npfuncs.py +++ b/pandas/tests/series/test_npfuncs.py @@ -29,7 +29,7 @@ def test_numpy_argwhere(index): s = Series(range(5), index=index, dtype=np.int64) - result = np.argwhere(s > 2) + result = np.argwhere(s > 2).astype(np.int64) expected = np.array([[3], [4]], dtype=np.int64) tm.assert_numpy_array_equal(result, expected)