Skip to content

Commit ee514a0

Browse files
simonjayhawkinsJulianWgs
authored andcommitted
TST: [ArrowStringArray] more parameterised testing - part 2 (pandas-dev#40749)
1 parent 91507e1 commit ee514a0

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

pandas/tests/frame/methods/test_astype.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import numpy as np
44
import pytest
55

6+
import pandas.util._test_decorators as td
7+
68
import pandas as pd
79
from pandas import (
810
Categorical,
@@ -564,17 +566,25 @@ def test_astype_empty_dtype_dict(self):
564566
assert result is not df
565567

566568
@pytest.mark.parametrize(
567-
"df",
569+
"data, dtype",
568570
[
569-
DataFrame(Series(["x", "y", "z"], dtype="string")),
570-
DataFrame(Series(["x", "y", "z"], dtype="category")),
571-
DataFrame(Series(3 * [Timestamp("2020-01-01", tz="UTC")])),
572-
DataFrame(Series(3 * [Interval(0, 1)])),
571+
(["x", "y", "z"], "string"),
572+
pytest.param(
573+
["x", "y", "z"],
574+
"arrow_string",
575+
marks=td.skip_if_no("pyarrow", min_version="1.0.0"),
576+
),
577+
(["x", "y", "z"], "category"),
578+
(3 * [Timestamp("2020-01-01", tz="UTC")], None),
579+
(3 * [Interval(0, 1)], None),
573580
],
574581
)
575582
@pytest.mark.parametrize("errors", ["raise", "ignore"])
576-
def test_astype_ignores_errors_for_extension_dtypes(self, df, errors):
583+
def test_astype_ignores_errors_for_extension_dtypes(self, data, dtype, errors):
577584
# https://github.com/pandas-dev/pandas/issues/35471
585+
from pandas.core.arrays.string_arrow import ArrowStringDtype # noqa: F401
586+
587+
df = DataFrame(Series(data, dtype=dtype))
578588
if errors == "ignore":
579589
expected = df
580590
result = df.astype(float, errors=errors)

pandas/tests/frame/methods/test_select_dtypes.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ def test_select_dtypes_typecodes(self):
391391
(
392392
(np.array([1, 2], dtype=np.int32), True),
393393
(pd.array([1, 2], dtype="Int32"), True),
394-
(pd.array(["a", "b"], dtype="string"), False),
395394
(DummyArray([1, 2], dtype=DummyDtype(numeric=True)), True),
396395
(DummyArray([1, 2], dtype=DummyDtype(numeric=False)), False),
397396
),
@@ -402,3 +401,9 @@ def test_select_dtypes_numeric(self, arr, expected):
402401
df = DataFrame(arr)
403402
is_selected = df.select_dtypes(np.number).shape == df.shape
404403
assert is_selected == expected
404+
405+
def test_select_dtypes_numeric_nullable_string(self, nullable_string_dtype):
406+
arr = pd.array(["a", "b"], dtype=nullable_string_dtype)
407+
df = DataFrame(arr)
408+
is_selected = df.select_dtypes(np.number).shape == df.shape
409+
assert not is_selected

pandas/tests/indexing/test_check_indexer.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def test_int_raise_missing_values(indexer):
7878
np.array([1.0, 2.0], dtype="float64"),
7979
np.array([True, False], dtype=object),
8080
pd.Index([True, False], dtype=object),
81-
pd.array(["a", "b"], dtype="string"),
8281
],
8382
)
8483
def test_raise_invalid_array_dtypes(indexer):
@@ -89,6 +88,15 @@ def test_raise_invalid_array_dtypes(indexer):
8988
check_array_indexer(arr, indexer)
9089

9190

91+
def test_raise_nullable_string_dtype(nullable_string_dtype):
92+
indexer = pd.array(["a", "b"], dtype=nullable_string_dtype)
93+
arr = np.array([1, 2, 3])
94+
95+
msg = "arrays used as indices must be of integer or boolean type"
96+
with pytest.raises(IndexError, match=msg):
97+
check_array_indexer(arr, indexer)
98+
99+
92100
@pytest.mark.parametrize("indexer", [None, Ellipsis, slice(0, 3), (None,)])
93101
def test_pass_through_non_array_likes(indexer):
94102
arr = np.array([1, 2, 3])

0 commit comments

Comments
 (0)