-
Notifications
You must be signed in to change notification settings - Fork 159
fix: Use metaclass for safe DType
attr access
#2025
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b1a0d6
fix(RFC): Use metaclass for safe `DType` attr access
dangotbanned 38e7bd6
Merge remote-tracking branch 'upstream/main' into dtype-meta
dangotbanned 473cd52
Merge branch 'main' into dtype-meta
dangotbanned 12ac889
chore: add `_DurationMeta`
dangotbanned ed4c412
refactor: upgrade `_pandas`
dangotbanned 3e122c6
refactor: upgrade `_arrow`
dangotbanned 1db895e
refactor: "upgrade" `_duckdb`
dangotbanned 82195dd
refactor: upgrade `_spark_like`
dangotbanned 38812e6
chore: remove comment
dangotbanned e8e9a97
refactor: simplify `__eq__`
dangotbanned ed385a9
Merge branch 'main' into dtype-meta
dangotbanned 3b42f16
Merge remote-tracking branch 'upstream/main' into dtype-meta
dangotbanned 50a43f3
fix: maybe fix typo "dt_time_unit"
dangotbanned File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from narwhals.exceptions import NarwhalsError | ||
from narwhals.exceptions import ShapeError | ||
from narwhals.utils import import_dtypes_module | ||
from narwhals.utils import isinstance_or_issubclass | ||
|
||
if TYPE_CHECKING: | ||
from narwhals._polars.dataframe import PolarsDataFrame | ||
|
@@ -190,13 +191,10 @@ def narwhals_to_native_dtype( | |
if dtype == dtypes.Decimal: | ||
msg = "Casting to Decimal is not supported yet." | ||
raise NotImplementedError(msg) | ||
if dtype == dtypes.Datetime or isinstance(dtype, dtypes.Datetime): | ||
dt_time_unit: TimeUnit = getattr(dtype, "time_unit", "us") | ||
dt_time_zone = getattr(dtype, "time_zone", None) | ||
return pl.Datetime(dt_time_unit, dt_time_zone) # type: ignore[arg-type] | ||
if dtype == dtypes.Duration or isinstance(dtype, dtypes.Duration): | ||
du_time_unit: TimeUnit = getattr(dtype, "time_unit", "us") | ||
return pl.Duration(time_unit=du_time_unit) # type: ignore[arg-type] | ||
if isinstance_or_issubclass(dtype, dtypes.Datetime): | ||
return pl.Datetime(dtype.time_unit, dtype.time_zone) # type: ignore[arg-type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if isinstance_or_issubclass(dtype, dtypes.Duration): | ||
return pl.Duration(dtype.time_unit) # type: ignore[arg-type] | ||
if dtype == dtypes.List: | ||
return pl.List(narwhals_to_native_dtype(dtype.inner, version, backend_version)) # type: ignore[union-attr] | ||
if dtype == dtypes.Struct: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.