Skip to content

Commit 77a2326

Browse files
jbrockmendeljorisvandenbossche
authored andcommitted
TST (string): copy/view tests (#59702)
1 parent c083ed0 commit 77a2326

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
@@ -453,7 +453,7 @@ def __eq__(self, other: object) -> bool:
453453
# Because left and right have the same length and are unique,
454454
# `indexer` not having any -1s implies that there is a
455455
# bijection between `left` and `right`.
456-
return (indexer != -1).all()
456+
return bool((indexer != -1).all())
457457

458458
# With object-dtype we need a comparison that identifies
459459
# 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,
@@ -285,10 +283,9 @@ def test_dataframe_from_dict_of_series_with_reindex(dtype):
285283
assert np.shares_memory(arr_before, arr_after)
286284

287285

288-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
289286
@pytest.mark.parametrize("cons", [Series, Index])
290287
@pytest.mark.parametrize(
291-
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], None)]
288+
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], object)]
292289
)
293290
def test_dataframe_from_series_or_index(
294291
using_copy_on_write, warn_copy_on_write, data, dtype, cons

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(using_copy_on_write):
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

@@ -41,10 +40,9 @@ def test_concat_frames(using_copy_on_write):
4140
tm.assert_frame_equal(df, df_orig)
4241

4342

44-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
4543
def test_concat_frames_updating_input(using_copy_on_write):
46-
df = DataFrame({"b": ["a"] * 3})
47-
df2 = DataFrame({"a": ["a"] * 3})
44+
df = DataFrame({"b": ["a"] * 3}, dtype=object)
45+
df2 = DataFrame({"a": ["a"] * 3}, dtype=object)
4846
result = concat([df, df2], axis=1)
4947

5048
if using_copy_on_write:
@@ -203,7 +201,7 @@ def test_concat_copy_keyword(using_copy_on_write, copy):
203201
assert not np.shares_memory(get_array(df2, "b"), get_array(result, "b"))
204202

205203

206-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
204+
# @pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
207205
@pytest.mark.parametrize(
208206
"func",
209207
[
@@ -212,8 +210,8 @@ def test_concat_copy_keyword(using_copy_on_write, copy):
212210
],
213211
)
214212
def test_merge_on_key(using_copy_on_write, func):
215-
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
216-
df2 = DataFrame({"key": ["a", "b", "c"], "b": [4, 5, 6]})
213+
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
214+
df2 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "b": [4, 5, 6]})
217215
df1_orig = df1.copy()
218216
df2_orig = df2.copy()
219217

@@ -267,7 +265,6 @@ def test_merge_on_index(using_copy_on_write):
267265
tm.assert_frame_equal(df2, df2_orig)
268266

269267

270-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
271268
@pytest.mark.parametrize(
272269
"func, how",
273270
[
@@ -276,8 +273,8 @@ def test_merge_on_index(using_copy_on_write):
276273
],
277274
)
278275
def test_merge_on_key_enlarging_one(using_copy_on_write, func, how):
279-
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
280-
df2 = DataFrame({"key": ["a", "b"], "b": [4, 5]})
276+
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
277+
df2 = DataFrame({"key": Series(["a", "b"], dtype=object), "b": [4, 5]})
281278
df1_orig = df1.copy()
282279
df2_orig = df2.copy()
283280

@@ -321,9 +318,13 @@ def test_merge_copy_keyword(using_copy_on_write, copy):
321318
assert not np.shares_memory(get_array(df2, "b"), get_array(result, "b"))
322319

323320

324-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
321+
@pytest.mark.xfail(
322+
using_string_dtype() and HAS_PYARROW,
323+
reason="TODO(infer_string); result.index infers str dtype while both "
324+
"df1 and df2 index are object.",
325+
)
325326
def test_join_on_key(using_copy_on_write):
326-
df_index = Index(["a", "b", "c"], name="key")
327+
df_index = Index(["a", "b", "c"], name="key", dtype=object)
327328

328329
df1 = DataFrame({"a": [1, 2, 3]}, index=df_index.copy(deep=True))
329330
df2 = DataFrame({"b": [4, 5, 6]}, index=df_index.copy(deep=True))
@@ -355,9 +356,8 @@ def test_join_on_key(using_copy_on_write):
355356
tm.assert_frame_equal(df2, df2_orig)
356357

357358

358-
@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
359359
def test_join_multiple_dataframes_on_key(using_copy_on_write):
360-
df_index = Index(["a", "b", "c"], name="key")
360+
df_index = Index(["a", "b", "c"], name="key", dtype=object)
361361

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

pandas/tests/copy_view/test_internals.py

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

4-
from pandas._config import using_string_dtype
5-
64
import pandas.util._test_decorators as td
75

86
import pandas as pd
9-
from pandas import DataFrame
7+
from pandas import (
8+
DataFrame,
9+
Series,
10+
)
1011
import pandas._testing as tm
1112
from pandas.tests.copy_view.util import get_array
1213

@@ -78,7 +79,6 @@ def test_switch_options():
7879

7980

8081
@td.skip_array_manager_invalid_test
81-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
8282
@pytest.mark.parametrize("dtype", [np.intp, np.int8])
8383
@pytest.mark.parametrize(
8484
"locs, arr",
@@ -105,7 +105,7 @@ def test_iset_splits_blocks_inplace(using_copy_on_write, locs, arr, dtype):
105105
"c": [7, 8, 9],
106106
"d": [10, 11, 12],
107107
"e": [13, 14, 15],
108-
"f": ["a", "b", "c"],
108+
"f": Series(["a", "b", "c"], dtype=object),
109109
},
110110
)
111111
arr = arr.astype(dtype)

pandas/tests/dtypes/test_dtypes.py

-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import pytest
66
import pytz
77

8-
from pandas._config import using_string_dtype
9-
108
from pandas._libs.tslibs.dtypes import NpyDatetimeUnit
119

1210
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("ordered1", [True, False, None])
966963
@pytest.mark.parametrize("ordered2", [True, False, None])
967964
def test_categorical_equality(self, ordered1, ordered2):

0 commit comments

Comments
 (0)