Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pandas_2.0_feature_branch' int…
Browse files Browse the repository at this point in the history
…o pandas_2.0_feature_branch
  • Loading branch information
galipremsagar committed Apr 19, 2023
2 parents a31d62c + 8e8a1ea commit 69af242
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
14 changes: 14 additions & 0 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,20 @@ def _make_operands_and_index_for_binop(
if _is_scalar_or_zero_d_array(other):
rhs = {name: other for name in self._data}
elif isinstance(other, Series):
if (
not can_reindex
and fn in cudf.utils.utils._EQUALITY_OPS
and (
not self._data.to_pandas_index().equals(
other.index.to_pandas()
)
)
):
raise ValueError(
"Can only compare DataFrame & Series objects "
"whose columns & index are same respectively, "
"please reindex."
)
rhs = dict(zip(other.index.values_host, other.values_host))
# For keys in right but not left, perform binops between NaN (not
# NULL!) and the right value (result is NaN).
Expand Down
46 changes: 20 additions & 26 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import re
import string
import textwrap
import warnings
from collections import OrderedDict, defaultdict
from copy import copy

Expand Down Expand Up @@ -5338,7 +5337,9 @@ def test_cov_nans():
cudf.Series([4, 2, 3], index=cudf.core.index.RangeIndex(0, 3)),
pytest.param(
cudf.Series([4, 2, 3, 4, 5], index=["a", "b", "d", "0", "12"]),
marks=pytest_xfail,
marks=pytest.mark.xfail(
not PANDAS_GE_200, reason="works only with pandas 2.0+"
),
),
],
)
Expand All @@ -5361,39 +5362,32 @@ def test_cov_nans():
],
)
def test_df_sr_binop(gsr, colnames, op):
# Anywhere that the column names of the DataFrame don't match the index
# names of the Series will trigger a deprecated reindexing. Since this
# behavior is deprecated in pandas, this test is temporarily silencing
# those warnings until cudf updates to pandas 2.0 as its compatibility
# target, at which point a large number of the parametrizations can be
# removed altogether (along with this warnings filter).
with warnings.catch_warnings():
assert version.parse(pd.__version__) < version.parse("2.0.0")
warnings.filterwarnings(
action="ignore",
category=FutureWarning,
message=(
"Automatic reindexing on DataFrame vs Series comparisons is "
"deprecated"
),
)
data = [[3.0, 2.0, 5.0], [3.0, None, 5.0], [6.0, 7.0, np.nan]]
data = dict(zip(colnames, data))
data = [[3.0, 2.0, 5.0], [3.0, None, 5.0], [6.0, 7.0, np.nan]]
data = dict(zip(colnames, data))

gsr = gsr.astype("float64")
gsr = gsr.astype("float64")

gdf = cudf.DataFrame(data)
pdf = gdf.to_pandas(nullable=True)
gdf = cudf.DataFrame(data)
pdf = gdf.to_pandas(nullable=True)

psr = gsr.to_pandas(nullable=True)
psr = gsr.to_pandas(nullable=True)

try:
expect = op(pdf, psr)
except ValueError:
with pytest.raises(ValueError):
op(gdf, gsr)
with pytest.raises(ValueError):
op(psr, pdf)
with pytest.raises(ValueError):
op(gsr, gdf)
else:
got = op(gdf, gsr).to_pandas(nullable=True)
assert_eq(expect, got, check_dtype=False)
assert_eq(expect, got, check_dtype=False, check_like=True)

expect = op(psr, pdf)
got = op(gsr, gdf).to_pandas(nullable=True)
assert_eq(expect, got, check_dtype=False)
assert_eq(expect, got, check_dtype=False, check_like=True)


@pytest_unmark_spilling
Expand Down

0 comments on commit 69af242

Please sign in to comment.