Skip to content

Commit 0e198c3

Browse files
alexander-beedieritchie46
authored andcommitted
feat(python): Add "drop_empty_cols" parameter for read_excel and read_ods (#20430)
1 parent 33580b8 commit 0e198c3

File tree

4 files changed

+140
-38
lines changed

4 files changed

+140
-38
lines changed

py-polars/polars/_utils/various.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import sys
77
import warnings
8+
from collections import Counter
89
from collections.abc import (
910
Collection,
1011
Generator,
@@ -42,7 +43,7 @@
4243
from polars.dependencies import numpy as np
4344

4445
if TYPE_CHECKING:
45-
from collections.abc import Iterator, Reversible
46+
from collections.abc import Iterator, MutableMapping, Reversible
4647

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

249250

251+
def deduplicate_names(names: Iterable[str]) -> list[str]:
252+
"""Ensure name uniqueness by appending a counter to subsequent duplicates."""
253+
seen: MutableMapping[str, int] = Counter()
254+
deduped = []
255+
for nm in names:
256+
deduped.append(f"{nm}{seen[nm] - 1}" if nm in seen else nm)
257+
seen[nm] += 1
258+
return deduped
259+
260+
250261
@overload
251262
def scale_bytes(sz: int, unit: SizeUnit) -> int | float: ...
252263

0 commit comments

Comments
 (0)