Skip to content

Commit

Permalink
fixup cast to string for pandas (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Jun 4, 2024
1 parent ad97d7e commit ac36801
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions narwhals/_pandas_like/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def reverse_translate_dtype( # noqa: PLR0915
from narwhals import dtypes

dtype_backend = get_dtype_backend(starting_dtype, implementation)

if isinstance_or_issubclass(dtype, dtypes.Float64):
if dtype_backend == "pyarrow-nullable":
return "Float64[pyarrow]"
Expand Down Expand Up @@ -514,7 +513,7 @@ def reverse_translate_dtype( # noqa: PLR0915
if dtype_backend == "pandas-nullable":
return "string"
else:
return object
return str
if isinstance_or_issubclass(dtype, dtypes.Boolean):
if dtype_backend == "pyarrow-nullable":
return "boolean[pyarrow]"
Expand Down
18 changes: 18 additions & 0 deletions tests/series/cast_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pandas as pd
import polars as pl

import narwhals as nw


def test_cast_253() -> None:
df_polars = pl.DataFrame({"a": [1]})
result = nw.from_native(df_polars, eager_only=True).select(
nw.col("a").cast(nw.String) + "hi"
)["a"][0]
assert result == "1hi"

df_pandas = pd.DataFrame({"a": [1]})
result = nw.from_native(df_pandas, eager_only=True).select(
nw.col("a").cast(nw.String) + "hi"
)["a"][0]
assert result == "1hi"

0 comments on commit ac36801

Please sign in to comment.