Skip to content

Commit

Permalink
try fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Dec 17, 2024
1 parent 2118191 commit 262295a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions xarray/conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,10 @@ def _update_bounds_encoding(variables: T_Variables) -> None:


T = TypeVar("T")
U = TypeVar("U")


def _item_or_default(obj: Mapping[Any, T] | T, key: Hashable, default: T) -> T:
def _item_or_default(obj: Mapping[Any, T | U] | T, key: Hashable, default: T) -> T | U:
"""
Return item by key if obj is mapping and key is present, else return default value.
"""
Expand Down Expand Up @@ -461,7 +462,7 @@ def decode_cf(
obj: T_DatasetOrAbstractstore,
concat_characters: bool = True,
mask_and_scale: bool = True,
decode_times: bool | CFDatetimeCoder = True,
decode_times: bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder] = True,
decode_coords: bool | Literal["coordinates", "all"] = True,
drop_variables: T_DropVariables = None,
use_cftime: bool | None = None,
Expand All @@ -480,7 +481,7 @@ def decode_cf(
mask_and_scale : bool, optional
Lazily scale (using scale_factor and add_offset) and mask
(using _FillValue).
decode_times : bool or CFDatetimeCoder, optional
decode_times : bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder], optional
Decode cf times (e.g., integers since "hours since 2000-01-01") to
np.datetime64.
decode_coords : bool or {"coordinates", "all"}, optional
Expand All @@ -505,8 +506,10 @@ def decode_cf(
represented using ``np.datetime64[ns]`` objects. If False, always
decode times to ``np.datetime64[ns]`` objects; if this is not possible
raise an error.
Usage of use_cftime as kwarg is deprecated, please initialize it with
CFDatetimeCoder and ``decode_times``.
.. deprecated:: 2024.12.0
Please initialize it with ``CFDatetimeCoder`` and ``decode_times`` kwarg.
decode_timedelta : bool, optional
If True, decode variables and coordinates with time units in
{"days", "hours", "minutes", "seconds", "milliseconds", "microseconds"}
Expand Down Expand Up @@ -560,7 +563,7 @@ def cf_decoder(
attributes: T_Attrs,
concat_characters: bool = True,
mask_and_scale: bool = True,
decode_times: bool | CFDatetimeCoder = True,
decode_times: bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder] = True,
) -> tuple[T_Variables, T_Attrs]:
"""
Decode a set of CF encoded variables and attributes.
Expand All @@ -577,7 +580,7 @@ def cf_decoder(
mask_and_scale : bool
Lazily scale (using scale_factor and add_offset) and mask
(using _FillValue).
decode_times : bool | CFDatetimeCoder
decode_times : bool | CFDatetimeCoder | Mapping[str, bool | CFDatetimeCoder]
Decode cf times ("hours since 2000-01-01") to np.datetime64.
Returns
Expand Down

0 comments on commit 262295a

Please sign in to comment.