Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions pandas/core/reshape/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
Hashable,
Iterable,
)
import itertools
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -185,7 +184,7 @@ def check_len(item, name: str) -> None:
check_len(prefix_sep, "prefix_sep")

if isinstance(prefix, str):
prefix = itertools.cycle([prefix])
prefix = [prefix] * len(data_to_encode.columns)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use itertools.repeat?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok,i will edit it right now.Thanks for your guidance

if isinstance(prefix, dict):
prefix = [prefix[col] for col in data_to_encode.columns]

Expand All @@ -194,7 +193,7 @@ def check_len(item, name: str) -> None:

# validate separators
if isinstance(prefix_sep, str):
prefix_sep = itertools.cycle([prefix_sep])
prefix_sep = [prefix_sep] * len(data_to_encode.columns)
elif isinstance(prefix_sep, dict):
prefix_sep = [prefix_sep[col] for col in data_to_encode.columns]

Expand All @@ -211,7 +210,9 @@ def check_len(item, name: str) -> None:
# columns to prepend to result.
with_dummies = [data.select_dtypes(exclude=dtypes_to_encode)]

for col, pre, sep in zip(data_to_encode.items(), prefix, prefix_sep):
for col, pre, sep in zip(
data_to_encode.items(), prefix, prefix_sep, strict=True
):
# col is (column_name, column), use just column data here
dummy = _get_dummies_1d(
col[1],
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def melt(
missing = idx == -1
if missing.any():
missing_labels = [
lab for lab, not_found in zip(labels, missing) if not_found
lab for lab, not_found in zip(labels, missing, strict=True) if not_found
]
raise KeyError(
"The following id_vars or value_vars are not present in "
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,8 @@ def crosstab(
from pandas import DataFrame

data = {
**dict(zip(unique_rownames, index)),
**dict(zip(unique_colnames, columns)),
**dict(zip(unique_rownames, index, strict=True)),
**dict(zip(unique_colnames, columns, strict=True)),
}
df = DataFrame(data, index=common_idx)

Expand Down
Loading