Skip to content

Commit

Permalink
speed up?
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Mar 18, 2024
1 parent 0e8c4da commit 619c19b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions narwhals/pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ def __init__(
dataframe: Any,
*,
implementation: str,
validate: bool = True,
) -> None:
if validate:
self._validate_columns(dataframe.columns)
self._validate_columns(dataframe.columns)
self._dataframe = dataframe
self._implementation = implementation

def _validate_columns(self, columns: Sequence[str]) -> None:
counter = collections.Counter(columns)
for col, count in counter.items():
if count > 1:
msg = f"Expected unique column names, got {col!r} {count} time(s)"
raise ValueError(
msg,
)
if len(columns) != len(set(columns)):
counter = collections.Counter(columns)
for col, count in counter.items():
if count > 1:
msg = f"Expected unique column names, got {col!r} {count} time(s)"
raise ValueError(
msg,
)

def _validate_booleanness(self) -> None:
if not (
Expand All @@ -59,7 +58,6 @@ def _from_dataframe(self, df: Any) -> Self:
return self.__class__(
df,
implementation=self._implementation,
validate=False,
)

def __getitem__(self, column_name: str) -> PandasSeries:
Expand Down

0 comments on commit 619c19b

Please sign in to comment.