Skip to content

Commit 193ab6e

Browse files
authored
Adjust test_binops for pandas 2.2 (#15078)
2 tests needed to be adjusted due to pandas changes in behaviors in pandas-dev/pandas#57447 and pandas-dev/pandas#57448 Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - GALI PREM SAGAR (https://github.com/galipremsagar) URL: #15078
1 parent 077eec4 commit 193ab6e

File tree

2 files changed

+72
-28
lines changed

2 files changed

+72
-28
lines changed

python/cudf/cudf/core/column/datetime.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,7 @@ def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
567567
if other is NotImplemented:
568568
return NotImplemented
569569
if isinstance(other, cudf.DateOffset):
570-
return other._datetime_binop(self, op, reflect=reflect).astype(
571-
self.dtype
572-
)
570+
return other._datetime_binop(self, op, reflect=reflect)
573571

574572
# We check this on `other` before reflection since we already know the
575573
# dtype of `self`.

python/cudf/cudf/tests/test_binops.py

+71-25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import cudf
1515
from cudf import Series
16+
from cudf.core._compat import PANDAS_GE_220
1617
from cudf.core.buffer.spill_manager import get_global_manager
1718
from cudf.core.index import as_index
1819
from cudf.testing import _utils as utils
@@ -824,11 +825,21 @@ def test_operator_func_between_series_logical(
824825
@pytest.mark.parametrize("fill_value", [None, 1.0])
825826
@pytest.mark.parametrize("use_cudf_scalar", [False, True])
826827
def test_operator_func_series_and_scalar_logical(
827-
dtype, func, has_nulls, scalar, fill_value, use_cudf_scalar
828+
request, dtype, func, has_nulls, scalar, fill_value, use_cudf_scalar
828829
):
829-
gdf_series = utils.gen_rand_series(
830-
dtype, 1000, has_nulls=has_nulls, stride=10000
830+
request.applymarker(
831+
pytest.mark.xfail(
832+
PANDAS_GE_220
833+
and fill_value == 1.0
834+
and scalar is np.nan
835+
and (has_nulls or (not has_nulls and func not in {"eq", "ne"})),
836+
reason="https://github.com/pandas-dev/pandas/issues/57447",
837+
)
831838
)
839+
if has_nulls:
840+
gdf_series = cudf.Series([-1.0, 0, cudf.NA, 1.1], dtype=dtype)
841+
else:
842+
gdf_series = cudf.Series([-1.0, 0, 10.5, 1.1], dtype=dtype)
832843
pdf_series = gdf_series.to_pandas(nullable=True)
833844
gdf_series_result = getattr(gdf_series, func)(
834845
cudf.Scalar(scalar) if use_cudf_scalar else scalar,
@@ -1684,16 +1695,6 @@ def test_scalar_null_binops(op, dtype_l, dtype_r):
16841695
assert result.dtype == valid_result.dtype
16851696

16861697

1687-
@pytest.mark.parametrize(
1688-
"date_col",
1689-
[
1690-
[
1691-
"2000-01-01 00:00:00.012345678",
1692-
"2000-01-31 00:00:00.012345678",
1693-
"2000-02-29 00:00:00.012345678",
1694-
]
1695-
],
1696-
)
16971698
@pytest.mark.parametrize("n_periods", [0, 1, -1, 12, -12])
16981699
@pytest.mark.parametrize(
16991700
"frequency",
@@ -1714,8 +1715,40 @@ def test_scalar_null_binops(op, dtype_l, dtype_r):
17141715
)
17151716
@pytest.mark.parametrize("op", [operator.add, operator.sub])
17161717
def test_datetime_dateoffset_binaryop(
1717-
date_col, n_periods, frequency, dtype, op
1718+
request, n_periods, frequency, dtype, op
17181719
):
1720+
request.applymarker(
1721+
pytest.mark.xfail(
1722+
PANDAS_GE_220
1723+
and dtype in {"datetime64[ms]", "datetime64[s]"}
1724+
and frequency == "microseconds"
1725+
and n_periods == 0,
1726+
reason="https://github.com/pandas-dev/pandas/issues/57448",
1727+
)
1728+
)
1729+
request.applymarker(
1730+
pytest.mark.xfail(
1731+
not PANDAS_GE_220
1732+
and dtype in {"datetime64[ms]", "datetime64[s]"}
1733+
and frequency in ("microseconds", "nanoseconds")
1734+
and n_periods != 0,
1735+
reason="https://github.com/pandas-dev/pandas/pull/55595",
1736+
)
1737+
)
1738+
request.applymarker(
1739+
pytest.mark.xfail(
1740+
not PANDAS_GE_220
1741+
and dtype == "datetime64[us]"
1742+
and frequency == "nanoseconds"
1743+
and n_periods != 0,
1744+
reason="https://github.com/pandas-dev/pandas/pull/55595",
1745+
)
1746+
)
1747+
date_col = [
1748+
"2000-01-01 00:00:00.012345678",
1749+
"2000-01-31 00:00:00.012345678",
1750+
"2000-02-29 00:00:00.012345678",
1751+
]
17191752
gsr = cudf.Series(date_col, dtype=dtype)
17201753
psr = gsr.to_pandas()
17211754

@@ -1776,16 +1809,6 @@ def test_datetime_dateoffset_binaryop_multiple(date_col, kwargs, op):
17761809
utils.assert_eq(expect, got)
17771810

17781811

1779-
@pytest.mark.parametrize(
1780-
"date_col",
1781-
[
1782-
[
1783-
"2000-01-01 00:00:00.012345678",
1784-
"2000-01-31 00:00:00.012345678",
1785-
"2000-02-29 00:00:00.012345678",
1786-
]
1787-
],
1788-
)
17891812
@pytest.mark.parametrize("n_periods", [0, 1, -1, 12, -12])
17901813
@pytest.mark.parametrize(
17911814
"frequency",
@@ -1805,8 +1828,31 @@ def test_datetime_dateoffset_binaryop_multiple(date_col, kwargs, op):
18051828
["datetime64[ns]", "datetime64[us]", "datetime64[ms]", "datetime64[s]"],
18061829
)
18071830
def test_datetime_dateoffset_binaryop_reflected(
1808-
date_col, n_periods, frequency, dtype
1831+
request, n_periods, frequency, dtype
18091832
):
1833+
request.applymarker(
1834+
pytest.mark.xfail(
1835+
not PANDAS_GE_220
1836+
and dtype in {"datetime64[ms]", "datetime64[s]"}
1837+
and frequency in ("microseconds", "nanoseconds")
1838+
and n_periods != 0,
1839+
reason="https://github.com/pandas-dev/pandas/pull/55595",
1840+
)
1841+
)
1842+
request.applymarker(
1843+
pytest.mark.xfail(
1844+
not PANDAS_GE_220
1845+
and dtype == "datetime64[us]"
1846+
and frequency == "nanoseconds"
1847+
and n_periods != 0,
1848+
reason="https://github.com/pandas-dev/pandas/pull/55595",
1849+
)
1850+
)
1851+
date_col = [
1852+
"2000-01-01 00:00:00.012345678",
1853+
"2000-01-31 00:00:00.012345678",
1854+
"2000-02-29 00:00:00.012345678",
1855+
]
18101856
gsr = cudf.Series(date_col, dtype=dtype)
18111857
psr = gsr.to_pandas() # converts to nanos
18121858

0 commit comments

Comments
 (0)