Skip to content

Commit

Permalink
TST (string dtype): add explicit object vs str dtype to index fixture (
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche authored Oct 30, 2024
1 parent 2ead198 commit 7bd594c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ def _create_mi_with_dt64tz_level():


indices_dict = {
"string": Index([f"pandas_{i}" for i in range(10)]),
"object": Index([f"pandas_{i}" for i in range(10)], dtype=object),
"string": Index([f"pandas_{i}" for i in range(10)], dtype="str"),
"datetime": date_range("2020-01-01", periods=10),
"datetime-tz": date_range("2020-01-01", periods=10, tz="US/Pacific"),
"period": period_range("2020-01-01", periods=10, freq="D"),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_any_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_map_identity_mapping(index, request):
# GH#12766

result = index.map(lambda x: x)
if index.dtype == object and result.dtype == bool:
if index.dtype == object and (result.dtype == bool or result.dtype == "string"):
assert (index == result).all()
# TODO: could work that into the 'exact="equiv"'?
return # FIXME: doesn't belong in this file anymore!
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_old_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_ensure_copied_data(self, index):
"RangeIndex cannot be initialized from data, "
"MultiIndex and CategoricalIndex are tested separately"
)
elif index.dtype == object and index.inferred_type == "boolean":
elif index.dtype == object and index.inferred_type in ["boolean", "string"]:
init_kwargs["dtype"] = index.dtype

index_type = type(index)
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/indexes/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ def test_difference_base(self, sort, index):
first.difference([1, 2, 3], sort)

@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
def test_symmetric_difference(self, index):
def test_symmetric_difference(self, index, using_infer_string, request):
if (
using_infer_string
and index.dtype == "object"
and index.inferred_type == "string"
):
request.applymarker(pytest.mark.xfail(reason="TODO: infer_string"))
if isinstance(index, CategoricalIndex):
pytest.skip(f"Not relevant for {type(index).__name__}")
if len(index) < 2:
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_factorize_complex(self):
expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=complex)
tm.assert_numpy_array_equal(uniques, expected_uniques)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
def test_factorize(self, index_or_series_obj, sort):
obj = index_or_series_obj
result_codes, result_uniques = obj.factorize(sort=sort)
Expand Down

0 comments on commit 7bd594c

Please sign in to comment.