Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: narwhals_to_native_dtype raise if polars dtype is passed #1307

Merged
merged 3 commits into from
Nov 2, 2024

Conversation

FBruzzesi
Copy link
Member

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

Related issues

Checklist

  • Code follows style guide (ruff)
  • Tests added
  • Documented the changes

If you have comments or can explain your changes, please do so below.

@github-actions github-actions bot added the fix label Nov 2, 2024
@@ -76,6 +77,17 @@ def native_to_narwhals_dtype(dtype: Any, dtypes: DTypes) -> DType:


def narwhals_to_native_dtype(dtype: DType | type[DType], dtypes: DTypes) -> Any:
if (pl := get_polars()) is not None and isinstance(
dtype, (pl.DataType, pl.DataType.__class__)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pl.DataType.__class__ is a workaround since pl.DataTypeClass now raises a DeprecationWarning.

I think this is the best way to check for both pl.String() and pl.String: if "polars" in str(type(dtype)) was definitly not enough for both

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thanks!

Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice, love this kind of ergonomic improvement

@MarcoGorelli MarcoGorelli merged commit 2235bae into main Nov 2, 2024
20 checks passed
@FBruzzesi FBruzzesi deleted the fix/raise-non-narwhals-dtypes branch November 2, 2024 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: casting to pl.String gets ignored
2 participants