Skip to content

Commit ce56f2e

Browse files
[backport 2.3.x] TST (string dtype): add explicit object vs str dtype to index fixture (pandas-dev#60116) (pandas-dev#60136)
(cherry picked from commit 7bd594c)
1 parent 6654c02 commit ce56f2e

File tree

9 files changed

+17
-5
lines changed

9 files changed

+17
-5
lines changed

pandas/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ def _create_mi_with_dt64tz_level():
615615

616616

617617
indices_dict = {
618-
"string": Index([f"pandas_{i}" for i in range(100)]),
618+
"object": Index([f"pandas_{i}" for i in range(100)], dtype=object),
619+
"string": Index([f"pandas_{i}" for i in range(100)], dtype="str"),
619620
"datetime": date_range("2020-01-01", periods=100),
620621
"datetime-tz": date_range("2020-01-01", periods=100, tz="US/Pacific"),
621622
"period": period_range("2020-01-01", periods=100, freq="D"),

pandas/core/algorithms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ def value_counts_internal(
931931
# For backwards compatibility, we let Index do its normal type
932932
# inference, _except_ for if if infers from object to bool.
933933
idx = Index(keys)
934-
if idx.dtype == bool and keys.dtype == object:
934+
if idx.dtype in [bool, "string"] and keys.dtype == object:
935935
idx = idx.astype(object)
936936
elif (
937937
idx.dtype != keys.dtype # noqa: PLR1714 # # pylint: disable=R1714

pandas/tests/base/test_misc.py

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def test_searchsorted(request, index_or_series_obj):
165165
assert 0 <= index <= len(obj)
166166

167167

168+
@pytest.mark.filterwarnings(r"ignore:Dtype inference:FutureWarning")
168169
def test_access_by_position(index_flat):
169170
index = index_flat
170171

pandas/tests/indexes/test_any_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_map_identity_mapping(index, request):
4545
# GH#12766
4646

4747
result = index.map(lambda x: x)
48-
if index.dtype == object and result.dtype == bool:
48+
if index.dtype == object and result.dtype in [bool, "string"]:
4949
assert (index == result).all()
5050
# TODO: could work that into the 'exact="equiv"'?
5151
return # FIXME: doesn't belong in this file anymore!

pandas/tests/indexes/test_common.py

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_copy_and_deepcopy(self, index_flat):
147147
new_copy = index.copy(deep=True, name="banana")
148148
assert new_copy.name == "banana"
149149

150+
@pytest.mark.filterwarnings(r"ignore:Dtype inference:FutureWarning")
150151
def test_copy_name(self, index_flat):
151152
# GH#12309: Check that the "name" argument
152153
# passed at initialization is honored.

pandas/tests/indexes/test_old_base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_ensure_copied_data(self, index):
260260
"RangeIndex cannot be initialized from data, "
261261
"MultiIndex and CategoricalIndex are tested separately"
262262
)
263-
elif index.dtype == object and index.inferred_type == "boolean":
263+
elif index.dtype == object and index.inferred_type in ["boolean", "string"]:
264264
init_kwargs["dtype"] = index.dtype
265265

266266
index_type = type(index)
@@ -485,6 +485,7 @@ def test_delete_base(self, index):
485485
with pytest.raises(IndexError, match=msg):
486486
index.delete(length)
487487

488+
@pytest.mark.filterwarnings(r"ignore:Dtype inference:FutureWarning")
488489
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
489490
def test_equals(self, index):
490491
if isinstance(index, IntervalIndex):

pandas/tests/indexes/test_setops.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,13 @@ def test_difference_base(self, sort, index):
293293
first.difference([1, 2, 3], sort)
294294

295295
@pytest.mark.filterwarnings(r"ignore:PeriodDtype\[B\] is deprecated:FutureWarning")
296-
def test_symmetric_difference(self, index):
296+
def test_symmetric_difference(self, index, using_infer_string, request):
297+
if (
298+
using_infer_string
299+
and index.dtype == "object"
300+
and index.inferred_type == "string"
301+
):
302+
request.applymarker(pytest.mark.xfail(reason="TODO: infer_string"))
297303
if isinstance(index, CategoricalIndex):
298304
pytest.skip(f"Not relevant for {type(index).__name__}")
299305
if len(index) < 2:

pandas/tests/series/methods/test_map.py

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def test_map_category_string():
221221
tm.assert_series_equal(a.map(c), exp)
222222

223223

224+
@pytest.mark.filterwarnings(r"ignore:Dtype inference:FutureWarning")
224225
def test_map_empty(request, index):
225226
if isinstance(index, MultiIndex):
226227
request.applymarker(

pandas/tests/test_algos.py

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_factorize_complex(self):
6565
expected_uniques = np.array([(1 + 0j), (2 + 0j), (2 + 1j)], dtype=object)
6666
tm.assert_numpy_array_equal(uniques, expected_uniques)
6767

68+
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
6869
@pytest.mark.parametrize("sort", [True, False])
6970
def test_factorize(self, index_or_series_obj, sort):
7071
obj = index_or_series_obj

0 commit comments

Comments
 (0)