From 619c19beabb01a62e51eb83c9de95f11ad3de817 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Mon, 18 Mar 2024 21:00:45 +0000 Subject: [PATCH] speed up? --- narwhals/pandas_like/dataframe.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/narwhals/pandas_like/dataframe.py b/narwhals/pandas_like/dataframe.py index 5aeb7ce36..3f900f926 100644 --- a/narwhals/pandas_like/dataframe.py +++ b/narwhals/pandas_like/dataframe.py @@ -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 ( @@ -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: