Skip to content

TST: misplaced array tests #46136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get dropped?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, redundant with existing tests in tests.arrays.test_datetimelike

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)