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

feat(python): Add "drop_empty_cols" parameter for read_excel and read_ods #20430

Merged
merged 1 commit into from
Dec 24, 2024
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
13 changes: 12 additions & 1 deletion py-polars/polars/_utils/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sys
import warnings
from collections import Counter
from collections.abc import (
Collection,
Generator,
Expand Down Expand Up @@ -42,7 +43,7 @@
from polars.dependencies import numpy as np

if TYPE_CHECKING:
from collections.abc import Iterator, Reversible
from collections.abc import Iterator, MutableMapping, Reversible

from polars import DataFrame, Expr
from polars._typing import PolarsDataType, SizeUnit
Expand Down Expand Up @@ -247,6 +248,16 @@ def ordered_unique(values: Sequence[Any]) -> list[Any]:
return [v for v in values if not (v in seen or add_(v))]


def deduplicate_names(names: Iterable[str]) -> list[str]:
"""Ensure name uniqueness by appending a counter to subsequent duplicates."""
seen: MutableMapping[str, int] = Counter()
deduped = []
for nm in names:
deduped.append(f"{nm}{seen[nm] - 1}" if nm in seen else nm)
seen[nm] += 1
return deduped


@overload
def scale_bytes(sz: int, unit: SizeUnit) -> int | float: ...

Expand Down
Loading
Loading