Skip to content
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

[REVIEW] Deprecate DataFrame.iteritems and introduce .items #10298

Merged
merged 2 commits into from
Feb 15, 2022
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
12 changes: 11 additions & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_ITEMS", color="blue", domain="cudf_python")
def items(self):
"""Iterate over column names and series pairs"""
for k in self:
yield (k, self[k])
Expand Down Expand Up @@ -4570,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:
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 3 additions & 5 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down