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

chore(typing): resolve time unit/zone set invariance #2012

Merged
merged 4 commits into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions narwhals/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

if TYPE_CHECKING:
from types import ModuleType
from typing import AbstractSet as Set
from typing import Protocol

import pandas as pd
Expand Down Expand Up @@ -1242,15 +1243,15 @@ def check_column_names_are_unique(columns: list[str]) -> None:
def _parse_time_unit_and_time_zone(
time_unit: TimeUnit | Iterable[TimeUnit] | None,
time_zone: str | timezone | Iterable[str | timezone | None] | None,
) -> tuple[set[str], set[str | None]]:
time_units = (
) -> tuple[Set[TimeUnit], Set[str | None]]:
time_units: Set[TimeUnit] = (
{"ms", "us", "ns", "s"}
if time_unit is None
else {time_unit}
if isinstance(time_unit, str)
else set(time_unit)
)
time_zones: set[str | None] = (
time_zones: Set[str | None] = (
{None}
if time_zone is None
else {str(time_zone)}
Expand All @@ -1261,10 +1262,7 @@ def _parse_time_unit_and_time_zone(


def dtype_matches_time_unit_and_time_zone(
dtype: DType,
dtypes: DTypes,
time_units: set[str],
time_zones: set[str | None],
dtype: DType, dtypes: DTypes, time_units: Set[TimeUnit], time_zones: Set[str | None]
) -> bool:
return (
(dtype == dtypes.Datetime)
Expand Down
Loading