From be66fde4162cd50307d985316f1897dc789cbd95 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:34:01 -0700 Subject: [PATCH] Add test verifying copy --- python/cudf/cudf/core/indexed_frame.py | 2 +- python/cudf/cudf/tests/test_series.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index 1e27bcda4fc..d898eb4b9c3 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -1917,7 +1917,7 @@ def nans_to_nulls(self): converted = col.nans_to_nulls() if converted is col: converted = converted.copy() - result.append(col) + result.append(converted) return self._from_data_like_self( self._data._from_columns_like_self(result) ) diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index 323716d5fc3..f47c42d9a1d 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -2841,3 +2841,10 @@ def test_series_from_series_index_no_shallow_copy(): ser1 = cudf.Series(range(3), index=list("abc")) ser2 = cudf.Series(ser1) assert ser1.index is ser2.index + + +@pytest.mark.parametrize("value", [1, 1.1]) +def test_nans_to_nulls_noop_copies_column(value): + ser1 = cudf.Series([value]) + ser2 = ser1.nans_to_nulls() + assert ser1._column is not ser2._column