Skip to content

Commit e5cdbf4

Browse files
authored
TST (string): copy/view tests (#59702)
1 parent 59ebd4e commit e5cdbf4

File tree

5 files changed

+23
-29
lines changed

5 files changed

+23
-29
lines changed

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def __eq__(self, other: object) -> bool:
455455
# Because left and right have the same length and are unique,
456456
# `indexer` not having any -1s implies that there is a
457457
# bijection between `left` and `right`.
458-
return (indexer != -1).all()
458+
return bool((indexer != -1).all())
459459

460460
# With object-dtype we need a comparison that identifies
461461
# e.g. int(2) as distinct from float(2)

pandas/tests/copy_view/test_constructors.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas._config import using_string_dtype
5-
64
import pandas as pd
75
from pandas import (
86
DataFrame,
@@ -209,9 +207,8 @@ def test_dataframe_from_dict_of_series_with_reindex(dtype):
209207
assert np.shares_memory(arr_before, arr_after)
210208

211209

212-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
213210
@pytest.mark.parametrize(
214-
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], None)]
211+
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], object)]
215212
)
216213
def test_dataframe_from_series_or_index(data, dtype, index_or_series):
217214
obj = index_or_series(data, dtype=dtype)

pandas/tests/copy_view/test_functions.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
from pandas.tests.copy_view.util import get_array
1717

1818

19-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
2019
def test_concat_frames():
21-
df = DataFrame({"b": ["a"] * 3})
22-
df2 = DataFrame({"a": ["a"] * 3})
20+
df = DataFrame({"b": ["a"] * 3}, dtype=object)
21+
df2 = DataFrame({"a": ["a"] * 3}, dtype=object)
2322
df_orig = df.copy()
2423
result = concat([df, df2], axis=1)
2524

@@ -35,10 +34,9 @@ def test_concat_frames():
3534
tm.assert_frame_equal(df, df_orig)
3635

3736

38-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
3937
def test_concat_frames_updating_input():
40-
df = DataFrame({"b": ["a"] * 3})
41-
df2 = DataFrame({"a": ["a"] * 3})
38+
df = DataFrame({"b": ["a"] * 3}, dtype=object)
39+
df2 = DataFrame({"a": ["a"] * 3}, dtype=object)
4240
result = concat([df, df2], axis=1)
4341

4442
assert np.shares_memory(get_array(result, "b"), get_array(df, "b"))
@@ -155,7 +153,7 @@ def test_concat_copy_keyword():
155153
assert np.shares_memory(get_array(df2, "b"), get_array(result, "b"))
156154

157155

158-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
156+
# @pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
159157
@pytest.mark.parametrize(
160158
"func",
161159
[
@@ -164,8 +162,8 @@ def test_concat_copy_keyword():
164162
],
165163
)
166164
def test_merge_on_key(func):
167-
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
168-
df2 = DataFrame({"key": ["a", "b", "c"], "b": [4, 5, 6]})
165+
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
166+
df2 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "b": [4, 5, 6]})
169167
df1_orig = df1.copy()
170168
df2_orig = df2.copy()
171169

@@ -207,7 +205,6 @@ def test_merge_on_index():
207205
tm.assert_frame_equal(df2, df2_orig)
208206

209207

210-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
211208
@pytest.mark.parametrize(
212209
"func, how",
213210
[
@@ -216,8 +213,8 @@ def test_merge_on_index():
216213
],
217214
)
218215
def test_merge_on_key_enlarging_one(func, how):
219-
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
220-
df2 = DataFrame({"key": ["a", "b"], "b": [4, 5]})
216+
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
217+
df2 = DataFrame({"key": Series(["a", "b"], dtype=object), "b": [4, 5]})
221218
df1_orig = df1.copy()
222219
df2_orig = df2.copy()
223220

@@ -251,9 +248,13 @@ def test_merge_copy_keyword():
251248
assert np.shares_memory(get_array(df2, "b"), get_array(result, "b"))
252249

253250

254-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
251+
@pytest.mark.xfail(
252+
using_string_dtype() and HAS_PYARROW,
253+
reason="TODO(infer_string); result.index infers str dtype while both "
254+
"df1 and df2 index are object.",
255+
)
255256
def test_join_on_key():
256-
df_index = Index(["a", "b", "c"], name="key")
257+
df_index = Index(["a", "b", "c"], name="key", dtype=object)
257258

258259
df1 = DataFrame({"a": [1, 2, 3]}, index=df_index.copy(deep=True))
259260
df2 = DataFrame({"b": [4, 5, 6]}, index=df_index.copy(deep=True))
@@ -279,9 +280,8 @@ def test_join_on_key():
279280
tm.assert_frame_equal(df2, df2_orig)
280281

281282

282-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
283283
def test_join_multiple_dataframes_on_key():
284-
df_index = Index(["a", "b", "c"], name="key")
284+
df_index = Index(["a", "b", "c"], name="key", dtype=object)
285285

286286
df1 = DataFrame({"a": [1, 2, 3]}, index=df_index.copy(deep=True))
287287
dfs_list = [

pandas/tests/copy_view/test_internals.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import numpy as np
22
import pytest
33

4-
from pandas._config import using_string_dtype
5-
6-
from pandas import DataFrame
4+
from pandas import (
5+
DataFrame,
6+
Series,
7+
)
78
import pandas._testing as tm
89
from pandas.tests.copy_view.util import get_array
910

@@ -42,7 +43,6 @@ def test_consolidate():
4243
assert df.loc[0, "b"] == 0.1
4344

4445

45-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
4646
@pytest.mark.parametrize("dtype", [np.intp, np.int8])
4747
@pytest.mark.parametrize(
4848
"locs, arr",
@@ -68,7 +68,7 @@ def test_iset_splits_blocks_inplace(locs, arr, dtype):
6868
"c": [7, 8, 9],
6969
"d": [10, 11, 12],
7070
"e": [13, 14, 15],
71-
"f": ["a", "b", "c"],
71+
"f": Series(["a", "b", "c"], dtype=object),
7272
},
7373
)
7474
arr = arr.astype(dtype)

pandas/tests/dtypes/test_dtypes.py

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

7-
from pandas._config import using_string_dtype
8-
97
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
108

119
from pandas.core.dtypes.base import _registry as registry
@@ -961,7 +959,6 @@ def test_same_categories_different_order(self):
961959
c2 = CategoricalDtype(["b", "a"], ordered=True)
962960
assert c1 is not c2
963961

964-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
965962
@pytest.mark.parametrize("ordered2", [True, False, None])
966963
def test_categorical_equality(self, ordered, ordered2):
967964
# same categories, same order

0 commit comments

Comments
 (0)