Skip to content

Commit

Permalink
TST (string): copy/view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Sep 3, 2024
1 parent 57a4fb9 commit d46a800
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def __eq__(self, other: object) -> bool:
# Because left and right have the same length and are unique,
# `indexer` not having any -1s implies that there is a
# bijection between `left` and `right`.
return (indexer != -1).all()
return bool((indexer != -1).all())

# With object-dtype we need a comparison that identifies
# e.g. int(2) as distinct from float(2)
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/copy_view/test_constructors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,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 @@ -209,9 +207,8 @@ def test_dataframe_from_dict_of_series_with_reindex(dtype):
assert np.shares_memory(arr_before, arr_after)


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize(
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], None)]
"data, dtype", [([1, 2], None), ([1, 2], "int64"), (["a", "b"], object)]
)
def test_dataframe_from_series_or_index(data, dtype, index_or_series):
obj = index_or_series(data, dtype=dtype)
Expand Down
32 changes: 16 additions & 16 deletions pandas/tests/copy_view/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
from pandas.tests.copy_view.util import get_array


@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
def test_concat_frames():
df = DataFrame({"b": ["a"] * 3})
df2 = DataFrame({"a": ["a"] * 3})
df = DataFrame({"b": ["a"] * 3}, dtype=object)
df2 = DataFrame({"a": ["a"] * 3}, dtype=object)
df_orig = df.copy()
result = concat([df, df2], axis=1)

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


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

assert np.shares_memory(get_array(result, "b"), get_array(df, "b"))
Expand Down Expand Up @@ -155,7 +153,7 @@ def test_concat_copy_keyword():
assert np.shares_memory(get_array(df2, "b"), get_array(result, "b"))


@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
# @pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
@pytest.mark.parametrize(
"func",
[
Expand All @@ -164,8 +162,8 @@ def test_concat_copy_keyword():
],
)
def test_merge_on_key(func):
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
df2 = DataFrame({"key": ["a", "b", "c"], "b": [4, 5, 6]})
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
df2 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "b": [4, 5, 6]})
df1_orig = df1.copy()
df2_orig = df2.copy()

Expand Down Expand Up @@ -207,7 +205,6 @@ def test_merge_on_index():
tm.assert_frame_equal(df2, df2_orig)


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize(
"func, how",
[
Expand All @@ -216,8 +213,8 @@ def test_merge_on_index():
],
)
def test_merge_on_key_enlarging_one(func, how):
df1 = DataFrame({"key": ["a", "b", "c"], "a": [1, 2, 3]})
df2 = DataFrame({"key": ["a", "b"], "b": [4, 5]})
df1 = DataFrame({"key": Series(["a", "b", "c"], dtype=object), "a": [1, 2, 3]})
df2 = DataFrame({"key": Series(["a", "b"], dtype=object), "b": [4, 5]})
df1_orig = df1.copy()
df2_orig = df2.copy()

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


@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
@pytest.mark.xfail(
using_string_dtype() and HAS_PYARROW,
reason="TODO(infer_string); result.index infers str dtype while both "
"df1 and df2 index are object.",
)
def test_join_on_key():
df_index = Index(["a", "b", "c"], name="key")
df_index = Index(["a", "b", "c"], name="key", dtype=object)

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


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

df1 = DataFrame({"a": [1, 2, 3]}, index=df_index.copy(deep=True))
dfs_list = [
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/copy_view/test_internals.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas import DataFrame
from pandas import (
DataFrame,
Series,
)
import pandas._testing as tm
from pandas.tests.copy_view.util import get_array

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


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False)
@pytest.mark.parametrize("dtype", [np.intp, np.int8])
@pytest.mark.parametrize(
"locs, arr",
Expand All @@ -68,7 +68,7 @@ def test_iset_splits_blocks_inplace(locs, arr, dtype):
"c": [7, 8, 9],
"d": [10, 11, 12],
"e": [13, 14, 15],
"f": ["a", "b", "c"],
"f": Series(["a", "b", "c"], dtype=object),
},
)
arr = arr.astype(dtype)
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/dtypes/test_dtypes.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

from pandas._libs.tslibs.dtypes import NpyDatetimeUnit

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

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

0 comments on commit d46a800

Please sign in to comment.