Skip to content

Commit

Permalink
feat(python): Add "drop_empty_cols" parameter for read_excel and `r…
Browse files Browse the repository at this point in the history
…ead_ods` (#20430)
  • Loading branch information
alexander-beedie authored Dec 24, 2024
1 parent cd2da5b commit ae7e42d
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 38 deletions.
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

0 comments on commit ae7e42d

Please sign in to comment.