Skip to content

TST: Parameterize test_rank.py #45114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 82 additions & 54 deletions pandas/tests/frame/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,64 +94,92 @@ def test_frame_in_list(self):
with pytest.raises(ValueError, match=msg):
df in [None]

def test_comparison_invalid(self):
def check(df, df2):

for (x, y) in [(df, df2), (df2, df)]:
# we expect the result to match Series comparisons for
# == and !=, inequalities should raise
result = x == y
expected = DataFrame(
{col: x[col] == y[col] for col in x.columns},
index=x.index,
columns=x.columns,
)
tm.assert_frame_equal(result, expected)

result = x != y
expected = DataFrame(
{col: x[col] != y[col] for col in x.columns},
index=x.index,
columns=x.columns,
)
tm.assert_frame_equal(result, expected)

msgs = [
r"Invalid comparison between dtype=datetime64\[ns\] and ndarray",
"invalid type promotion",
(
# npdev 1.20.0
r"The DTypes <class 'numpy.dtype\[.*\]'> and "
r"<class 'numpy.dtype\[.*\]'> do not have a common DType."
),
]
msg = "|".join(msgs)
with pytest.raises(TypeError, match=msg):
x >= y
with pytest.raises(TypeError, match=msg):
x > y
with pytest.raises(TypeError, match=msg):
x < y
with pytest.raises(TypeError, match=msg):
x <= y

@pytest.mark.parametrize(
"arg, arg2",
[
[
{
"a": np.random.randint(10, size=10),
"b": pd.date_range("20010101", periods=10),
},
{
"a": np.random.randint(10, size=10),
"b": np.random.randint(10, size=10),
},
],
[
{
"a": np.random.randint(10, size=10),
"b": np.random.randint(10, size=10),
},
{
"a": np.random.randint(10, size=10),
"b": pd.date_range("20010101", periods=10),
},
],
[
{
"a": pd.date_range("20010101", periods=10),
"b": pd.date_range("20010101", periods=10),
},
{
"a": np.random.randint(10, size=10),
"b": np.random.randint(10, size=10),
},
],
[
{
"a": np.random.randint(10, size=10),
"b": pd.date_range("20010101", periods=10),
},
{
"a": pd.date_range("20010101", periods=10),
"b": pd.date_range("20010101", periods=10),
},
],
],
)
def test_comparison_invalid(self, arg, arg2):
# GH4968
# invalid date/int comparisons
df = DataFrame(np.random.randint(10, size=(10, 1)), columns=["a"])
df["dates"] = pd.date_range("20010101", periods=len(df))

df2 = df.copy()
df2["dates"] = df["a"]
check(df, df2)
x = DataFrame(arg)
y = DataFrame(arg2)
# we expect the result to match Series comparisons for
# == and !=, inequalities should raise
result = x == y
expected = DataFrame(
{col: x[col] == y[col] for col in x.columns},
index=x.index,
columns=x.columns,
)
tm.assert_frame_equal(result, expected)

df = DataFrame(np.random.randint(10, size=(10, 2)), columns=["a", "b"])
df2 = DataFrame(
{
"a": pd.date_range("20010101", periods=len(df)),
"b": pd.date_range("20100101", periods=len(df)),
}
result = x != y
expected = DataFrame(
{col: x[col] != y[col] for col in x.columns},
index=x.index,
columns=x.columns,
)
check(df, df2)
tm.assert_frame_equal(result, expected)

msgs = [
r"Invalid comparison between dtype=datetime64\[ns\] and ndarray",
"invalid type promotion",
(
# npdev 1.20.0
r"The DTypes <class 'numpy.dtype\[.*\]'> and "
r"<class 'numpy.dtype\[.*\]'> do not have a common DType."
),
]
msg = "|".join(msgs)
with pytest.raises(TypeError, match=msg):
x >= y
with pytest.raises(TypeError, match=msg):
x > y
with pytest.raises(TypeError, match=msg):
x < y
with pytest.raises(TypeError, match=msg):
x <= y

def test_timestamp_compare(self):
# make sure we can compare Timestamps on the right AND left hand side
Expand Down
Loading