diff --git a/narwhals/_pandas_like/dataframe.py b/narwhals/_pandas_like/dataframe.py index 69ae987d6..983abb78d 100644 --- a/narwhals/_pandas_like/dataframe.py +++ b/narwhals/_pandas_like/dataframe.py @@ -11,9 +11,7 @@ from narwhals._pandas_like.utils import translate_dtype from narwhals._pandas_like.utils import validate_dataframe_comparand from narwhals._pandas_like.utils import validate_indices -from narwhals.dependencies import get_pyarrow from narwhals.utils import flatten -from narwhals.utils import parse_version if TYPE_CHECKING: from collections.abc import Sequence @@ -36,7 +34,7 @@ def __init__( implementation: str, ) -> None: self._validate_columns(dataframe.columns) - self._dataframe = self._convert_object_dtypes(dataframe) + self._dataframe = dataframe self._implementation = implementation def __narwhals_dataframe__(self) -> Self: @@ -50,25 +48,6 @@ def __narwhals_namespace__(self) -> PandasNamespace: return PandasNamespace(self._implementation) - def _convert_object_dtypes(self, dataframe: Any) -> Any: - schema = dataframe.dtypes - if (schema != object).all(): - return dataframe - replacements = {} - for col in dataframe.columns: - if schema[col] != object: - continue - import pandas as pd # todo: generalise across pandas-like implementations - - if parse_version(pd.__version__) >= parse_version("2.0.0"): - if get_pyarrow() is not None: - replacements[col] = dataframe[col].astype("string[pyarrow]") - else: # pragma: no cover - replacements[col] = dataframe[col].astype("string[python]") - else: # pragma: no cover - pass - return dataframe.assign(**replacements) - def _validate_columns(self, columns: Sequence[str]) -> None: if len(columns) != len(set(columns)): counter = collections.Counter(columns) diff --git a/narwhals/_pandas_like/utils.py b/narwhals/_pandas_like/utils.py index 2b5031ab9..4b4b154fa 100644 --- a/narwhals/_pandas_like/utils.py +++ b/narwhals/_pandas_like/utils.py @@ -312,11 +312,7 @@ def translate_dtype(dtype: Any) -> DType: if str(dtype).startswith("datetime64"): # todo: different time units and time zones return dtypes.Datetime() - if dtype == "object": # pragma: no cover - import pandas as pd - - assert parse_version(pd.__version__) < parse_version("2.0.0") - # Should only happen for pandas pre 2.0.0 + if dtype == "object": return dtypes.String() msg = f"Unknown dtype: {dtype}" # pragma: no cover raise AssertionError(msg) diff --git a/tests/hypothesis/test_basic_arithmetic.py b/tests/hypothesis/test_basic_arithmetic.py index 9322aa922..64210ed42 100644 --- a/tests/hypothesis/test_basic_arithmetic.py +++ b/tests/hypothesis/test_basic_arithmetic.py @@ -2,6 +2,7 @@ import pandas as pd import polars as pl +import pytest from hypothesis import given from hypothesis import strategies as st from numpy.testing import assert_allclose @@ -21,6 +22,7 @@ max_size=3, ), ) # type: ignore[misc] +@pytest.mark.slow() def test_mean( integer: st.SearchStrategy[list[int]], floats: st.SearchStrategy[float],