Skip to content

Commit 2fe0c70

Browse files
authored
TST: misplaced array tests (#46136)
* REF: directory for PandasArray tests * REF: misplaced tests
1 parent e7d6846 commit 2fe0c70

File tree

5 files changed

+46
-59
lines changed

5 files changed

+46
-59
lines changed

pandas/tests/arrays/numpy_/__init__.py

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import numpy as np
2+
3+
from pandas.core.dtypes.common import is_scalar
4+
5+
import pandas as pd
6+
import pandas._testing as tm
7+
8+
9+
class TestSearchsorted:
10+
def test_searchsorted_numeric_dtypes_scalar(self, any_real_numpy_dtype):
11+
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
12+
result = arr.searchsorted(30)
13+
assert is_scalar(result)
14+
assert result == 2
15+
16+
result = arr.searchsorted([30])
17+
expected = np.array([2], dtype=np.intp)
18+
tm.assert_numpy_array_equal(result, expected)
19+
20+
def test_searchsorted_numeric_dtypes_vector(self, any_real_numpy_dtype):
21+
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
22+
result = arr.searchsorted([2, 30])
23+
expected = np.array([1, 2], dtype=np.intp)
24+
tm.assert_numpy_array_equal(result, expected)
25+
26+
def test_searchsorted_sorter(self, any_real_numpy_dtype):
27+
arr = pd.array([3, 1, 2], dtype=any_real_numpy_dtype)
28+
result = arr.searchsorted([0, 3], sorter=np.argsort(arr))
29+
expected = np.array([0, 2], dtype=np.intp)
30+
tm.assert_numpy_array_equal(result, expected)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pandas.core.dtypes.common import is_scalar
2+
3+
import pandas as pd
4+
5+
6+
class TestSearchsorted:
7+
def test_searchsorted(self, string_dtype):
8+
arr = pd.array(["a", "b", "c"], dtype=string_dtype)
9+
10+
result = arr.searchsorted("a", side="left")
11+
assert is_scalar(result)
12+
assert result == 0
13+
14+
result = arr.searchsorted("a", side="right")
15+
assert is_scalar(result)
16+
assert result == 1

pandas/tests/arrays/test_array.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import pandas as pd
1111
import pandas._testing as tm
1212
from pandas.api.extensions import register_extension_dtype
13-
from pandas.api.types import is_scalar
1413
from pandas.arrays import (
1514
BooleanArray,
1615
DatetimeArray,
@@ -391,61 +390,3 @@ def test_array_not_registered(registry_without_decimal):
391390
result = pd.array(data, dtype=DecimalDtype)
392391
expected = DecimalArray._from_sequence(data)
393392
tm.assert_equal(result, expected)
394-
395-
396-
class TestArrayAnalytics:
397-
def test_searchsorted(self, string_dtype):
398-
arr = pd.array(["a", "b", "c"], dtype=string_dtype)
399-
400-
result = arr.searchsorted("a", side="left")
401-
assert is_scalar(result)
402-
assert result == 0
403-
404-
result = arr.searchsorted("a", side="right")
405-
assert is_scalar(result)
406-
assert result == 1
407-
408-
def test_searchsorted_numeric_dtypes_scalar(self, any_real_numpy_dtype):
409-
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
410-
result = arr.searchsorted(30)
411-
assert is_scalar(result)
412-
assert result == 2
413-
414-
result = arr.searchsorted([30])
415-
expected = np.array([2], dtype=np.intp)
416-
tm.assert_numpy_array_equal(result, expected)
417-
418-
def test_searchsorted_numeric_dtypes_vector(self, any_real_numpy_dtype):
419-
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
420-
result = arr.searchsorted([2, 30])
421-
expected = np.array([1, 2], dtype=np.intp)
422-
tm.assert_numpy_array_equal(result, expected)
423-
424-
@pytest.mark.parametrize(
425-
"arr, val",
426-
[
427-
[
428-
pd.date_range("20120101", periods=10, freq="2D"),
429-
pd.Timestamp("20120102"),
430-
],
431-
[
432-
pd.date_range("20120101", periods=10, freq="2D", tz="Asia/Hong_Kong"),
433-
pd.Timestamp("20120102", tz="Asia/Hong_Kong"),
434-
],
435-
[
436-
pd.timedelta_range(start="1 day", end="10 days", periods=10),
437-
pd.Timedelta("2 days"),
438-
],
439-
],
440-
)
441-
def test_search_sorted_datetime64_scalar(self, arr, val):
442-
arr = pd.array(arr)
443-
result = arr.searchsorted(val)
444-
assert is_scalar(result)
445-
assert result == 1
446-
447-
def test_searchsorted_sorter(self, any_real_numpy_dtype):
448-
arr = pd.array([3, 1, 2], dtype=any_real_numpy_dtype)
449-
result = arr.searchsorted([0, 3], sorter=np.argsort(arr))
450-
expected = np.array([0, 2], dtype=np.intp)
451-
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)