From cf59671ecdd83cb1357b74418a2fc3ce1d41405e Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Tue, 15 Feb 2022 08:24:13 -0800 Subject: [PATCH 1/2] introduce items --- python/cudf/cudf/core/dataframe.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index fb15f8da8d9..5c0afa2b5c0 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -2066,6 +2066,16 @@ def __iter__(self): @annotate("DATAFRAME_ITERITEMS", color="blue", domain="cudf_python") def iteritems(self): + """Iterate over column names and series pairs""" + warnings.warn( + "iteritems is deprecated and will be removed in a future version. " + "Use .items instead.", + FutureWarning, + ) + return self.items() + + @annotate("DATAFRAME_ITERITEMS", color="blue", domain="cudf_python") + def items(self): """Iterate over column names and series pairs""" for k in self: yield (k, self[k]) From 53c95b8891fa147dfd49fecdd27fc822d5cb57c3 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Tue, 15 Feb 2022 08:29:10 -0800 Subject: [PATCH 2/2] updates --- python/cudf/cudf/core/dataframe.py | 4 ++-- python/cudf/cudf/tests/test_concat.py | 6 +++--- python/cudf/cudf/tests/test_dataframe.py | 8 +++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 5c0afa2b5c0..75c515df719 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -2074,7 +2074,7 @@ def iteritems(self): ) return self.items() - @annotate("DATAFRAME_ITERITEMS", color="blue", domain="cudf_python") + @annotate("DATAFRAME_ITEMS", color="blue", domain="cudf_python") def items(self): """Iterate over column names and series pairs""" for k in self: @@ -4580,7 +4580,7 @@ def from_pandas(cls, dataframe, nan_as_null=None): df = cls() # Set columns - for col_name, col_value in dataframe.iteritems(): + for col_name, col_value in dataframe.items(): # necessary because multi-index can return multiple # columns for a single key if len(col_value.shape) == 1: diff --git a/python/cudf/cudf/tests/test_concat.py b/python/cudf/cudf/tests/test_concat.py index b8724fe36f5..1ab5931fe5f 100644 --- a/python/cudf/cudf/tests/test_concat.py +++ b/python/cudf/cudf/tests/test_concat.py @@ -574,7 +574,7 @@ def test_concat_empty_dataframes(df, other, ignore_index): expected = pd.concat(other_pd, ignore_index=ignore_index) actual = gd.concat(other_gd, ignore_index=ignore_index) if expected.shape != df.shape: - for key, col in actual[actual.columns].iteritems(): + for key, col in actual[actual.columns].items(): if is_categorical_dtype(col.dtype): if not is_categorical_dtype(expected[key].dtype): # TODO: Pandas bug: @@ -1184,7 +1184,7 @@ def test_concat_join_empty_dataframes( ) if expected.shape != df.shape: if axis == 0: - for key, col in actual[actual.columns].iteritems(): + for key, col in actual[actual.columns].items(): if is_categorical_dtype(col.dtype): if not is_categorical_dtype(expected[key].dtype): # TODO: Pandas bug: @@ -1306,7 +1306,7 @@ def test_concat_join_empty_dataframes_axis_1( ) if expected.shape != df.shape: if axis == 0: - for key, col in actual[actual.columns].iteritems(): + for key, col in actual[actual.columns].items(): if is_categorical_dtype(col.dtype): expected[key] = expected[key].fillna("-1") actual[key] = col.astype("str").fillna("-1") diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index fb173bc0eab..fdb3f430a18 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -917,9 +917,7 @@ def test_dataframe_dtypes(): dtypes = pd.Series( [np.int32, np.float32, np.float64], index=["c", "a", "b"] ) - df = cudf.DataFrame( - {k: np.ones(10, dtype=v) for k, v in dtypes.iteritems()} - ) + df = cudf.DataFrame({k: np.ones(10, dtype=v) for k, v in dtypes.items()}) assert df.dtypes.equals(dtypes) @@ -1956,7 +1954,7 @@ def test_dataframe_reductions(data, axis, func, skipna): elif func not in cudf.core.dataframe._cupy_nan_methods_map: if skipna is False: expected_exception = NotImplementedError - elif any(col.nullable for name, col in gdf.iteritems()): + elif any(col.nullable for name, col in gdf.items()): expected_exception = ValueError elif func in ("cummin", "cummax"): expected_exception = AttributeError @@ -2134,7 +2132,7 @@ def test_iter(pdf, gdf): def test_iteritems(gdf): - for k, v in gdf.iteritems(): + for k, v in gdf.items(): assert k in gdf.columns assert isinstance(v, cudf.Series) assert_eq(v, gdf[k])