Skip to content

Commit

Permalink
TST: misplaced array tests (pandas-dev#46136)
Browse files Browse the repository at this point in the history
* REF: directory for PandasArray tests

* REF: misplaced tests
  • Loading branch information
jbrockmendel authored Feb 24, 2022
1 parent e7d6846 commit 2fe0c70
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 59 deletions.
Empty file.
30 changes: 30 additions & 0 deletions pandas/tests/arrays/numpy_/test_indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np

from pandas.core.dtypes.common import is_scalar

import pandas as pd
import pandas._testing as tm


class TestSearchsorted:
def test_searchsorted_numeric_dtypes_scalar(self, any_real_numpy_dtype):
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
result = arr.searchsorted(30)
assert is_scalar(result)
assert result == 2

result = arr.searchsorted([30])
expected = np.array([2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)

def test_searchsorted_numeric_dtypes_vector(self, any_real_numpy_dtype):
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
result = arr.searchsorted([2, 30])
expected = np.array([1, 2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)

def test_searchsorted_sorter(self, any_real_numpy_dtype):
arr = pd.array([3, 1, 2], dtype=any_real_numpy_dtype)
result = arr.searchsorted([0, 3], sorter=np.argsort(arr))
expected = np.array([0, 2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)
File renamed without changes.
16 changes: 16 additions & 0 deletions pandas/tests/arrays/string_/test_indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pandas.core.dtypes.common import is_scalar

import pandas as pd


class TestSearchsorted:
def test_searchsorted(self, string_dtype):
arr = pd.array(["a", "b", "c"], dtype=string_dtype)

result = arr.searchsorted("a", side="left")
assert is_scalar(result)
assert result == 0

result = arr.searchsorted("a", side="right")
assert is_scalar(result)
assert result == 1
59 changes: 0 additions & 59 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pandas as pd
import pandas._testing as tm
from pandas.api.extensions import register_extension_dtype
from pandas.api.types import is_scalar
from pandas.arrays import (
BooleanArray,
DatetimeArray,
Expand Down Expand Up @@ -391,61 +390,3 @@ def test_array_not_registered(registry_without_decimal):
result = pd.array(data, dtype=DecimalDtype)
expected = DecimalArray._from_sequence(data)
tm.assert_equal(result, expected)


class TestArrayAnalytics:
def test_searchsorted(self, string_dtype):
arr = pd.array(["a", "b", "c"], dtype=string_dtype)

result = arr.searchsorted("a", side="left")
assert is_scalar(result)
assert result == 0

result = arr.searchsorted("a", side="right")
assert is_scalar(result)
assert result == 1

def test_searchsorted_numeric_dtypes_scalar(self, any_real_numpy_dtype):
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
result = arr.searchsorted(30)
assert is_scalar(result)
assert result == 2

result = arr.searchsorted([30])
expected = np.array([2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)

def test_searchsorted_numeric_dtypes_vector(self, any_real_numpy_dtype):
arr = pd.array([1, 3, 90], dtype=any_real_numpy_dtype)
result = arr.searchsorted([2, 30])
expected = np.array([1, 2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
"arr, val",
[
[
pd.date_range("20120101", periods=10, freq="2D"),
pd.Timestamp("20120102"),
],
[
pd.date_range("20120101", periods=10, freq="2D", tz="Asia/Hong_Kong"),
pd.Timestamp("20120102", tz="Asia/Hong_Kong"),
],
[
pd.timedelta_range(start="1 day", end="10 days", periods=10),
pd.Timedelta("2 days"),
],
],
)
def test_search_sorted_datetime64_scalar(self, arr, val):
arr = pd.array(arr)
result = arr.searchsorted(val)
assert is_scalar(result)
assert result == 1

def test_searchsorted_sorter(self, any_real_numpy_dtype):
arr = pd.array([3, 1, 2], dtype=any_real_numpy_dtype)
result = arr.searchsorted([0, 3], sorter=np.argsort(arr))
expected = np.array([0, 2], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)

0 comments on commit 2fe0c70

Please sign in to comment.