Skip to content

Commit

Permalink
[backport 2.3.x] TST (string dtype): avoid explicit object dtype Inde…
Browse files Browse the repository at this point in the history
…x in fixture data (#60217) (#60225)


(cherry picked from commit 4b04a2f)
  • Loading branch information
jorisvandenbossche authored Nov 7, 2024
1 parent f8c7acc commit 168e353
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 14 deletions.
2 changes: 2 additions & 0 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ def shares_memory(left, right) -> bool:
if isinstance(left, MultiIndex):
return shares_memory(left._codes, right)
if isinstance(left, (Index, Series)):
if isinstance(right, (Index, Series)):
return shares_memory(left._values, right._values)
return shares_memory(left._values, right)

if isinstance(left, NDArrayBackedExtensionArray):
Expand Down
10 changes: 5 additions & 5 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def multiindex_year_month_day_dataframe_random_data():
"""
tdf = DataFrame(
np.random.default_rng(2).standard_normal((100, 4)),
columns=Index(list("ABCD"), dtype=object),
columns=Index(list("ABCD")),
index=date_range("2000-01-01", periods=100, freq="B"),
)
ymd = tdf.groupby([lambda x: x.year, lambda x: x.month, lambda x: x.day]).sum()
Expand Down Expand Up @@ -743,7 +743,7 @@ def string_series() -> Series:
"""
return Series(
np.arange(30, dtype=np.float64) * 1.1,
index=Index([f"i_{i}" for i in range(30)], dtype=object),
index=Index([f"i_{i}" for i in range(30)]),
name="series",
)

Expand All @@ -754,7 +754,7 @@ def object_series() -> Series:
Fixture for Series of dtype object with Index of unique strings
"""
data = [f"foo_{i}" for i in range(30)]
index = Index([f"bar_{i}" for i in range(30)], dtype=object)
index = Index([f"bar_{i}" for i in range(30)])
return Series(data, index=index, name="objects", dtype=object)


Expand Down Expand Up @@ -846,8 +846,8 @@ def int_frame() -> DataFrame:
"""
return DataFrame(
np.ones((30, 4), dtype=np.int64),
index=Index([f"foo_{i}" for i in range(30)], dtype=object),
columns=Index(list("ABCD"), dtype=object),
index=Index([f"foo_{i}" for i in range(30)]),
columns=Index(list("ABCD")),
)


Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/frame/methods/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

import pandas as pd
from pandas import (
DataFrame,
Expand Down Expand Up @@ -157,7 +155,6 @@ def test_align_series_condition(self):
expected = DataFrame({"a": [0, 2, 0], "b": [0, 5, 0]})
tm.assert_frame_equal(result, expected)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_align_int(self, int_frame):
# test other non-float types
other = DataFrame(index=range(5), columns=["A", "B", "C"])
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/frame/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,6 @@ def test_sum_bools(self):
# ----------------------------------------------------------------------
# Index of max / min

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.parametrize("skipna", [True, False])
@pytest.mark.parametrize("axis", [0, 1])
def test_idxmin(self, float_frame, int_frame, skipna, axis):
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/series/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ def test_setitem_with_expansion_type_promotion(self):
expected = Series([Timestamp("2016-01-01"), 3.0, "foo"], index=["a", "b", "c"])
tm.assert_series_equal(ser, expected)

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_setitem_not_contained(self, string_series):
# set item that's not contained
ser = string_series.copy()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def test_reindex(datetime_series, string_series):
identity = string_series.reindex(string_series.index)

assert np.may_share_memory(string_series.index, identity.index)
assert tm.shares_memory(string_series.index, identity.index)

assert identity.index.is_(string_series.index)
assert identity.index.identical(string_series.index)
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/series/methods/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

import pandas as pd
from pandas import Series
import pandas._testing as tm
Expand All @@ -26,7 +24,6 @@ def read_csv(self, path, **kwargs):

return out

@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_from_csv(self, datetime_series, string_series):
# freq doesn't round-trip
datetime_series.index = datetime_series.index._with_freq(None)
Expand Down

0 comments on commit 168e353

Please sign in to comment.