diff --git a/xarray/conventions.py b/xarray/conventions.py index 105171878c0..042a7f14032 100644 --- a/xarray/conventions.py +++ b/xarray/conventions.py @@ -7,6 +7,7 @@ import numpy as np +from xarray.coders import CFDatetimeCoder from xarray.coding import strings, times, variables from xarray.coding.variables import SerializationWarning, pop_to from xarray.core import indexing @@ -88,7 +89,7 @@ def encode_cf_variable( ensure_not_multiindex(var, name=name) for coder in [ - times.CFDatetimeCoder(), + CFDatetimeCoder(), times.CFTimedeltaCoder(), variables.CFScaleOffsetCoder(), variables.CFMaskCoder(), @@ -109,7 +110,7 @@ def decode_cf_variable( var: Variable, concat_characters: bool = True, mask_and_scale: bool = True, - decode_times: bool | times.CFDatetimeCoder = True, + decode_times: bool | CFDatetimeCoder = True, decode_endianness: bool = True, stack_char_dim: bool = True, use_cftime: bool | None = None, @@ -194,25 +195,25 @@ def decode_cf_variable( var = times.CFTimedeltaCoder().decode(var, name=name) if decode_times: # remove checks after end of deprecation cycle - if not isinstance(decode_times, times.CFDatetimeCoder): + if not isinstance(decode_times, CFDatetimeCoder): if use_cftime is not None: from warnings import warn warn( "Usage of 'use_cftime' as kwarg is deprecated. " - "Please initialize it with xarray.coders.CFDatetimeCoder and " + "Please initialize it with CFDatetimeCoder and " "'decode_times' kwarg.", DeprecationWarning, stacklevel=2, ) - decode_times = times.CFDatetimeCoder(use_cftime=use_cftime) + decode_times = CFDatetimeCoder(use_cftime=use_cftime) else: if use_cftime is not None: raise TypeError( "Usage of 'use_cftime' as kwarg is not allowed, " "if 'decode_times' is initialized with " - "xarray.coders.CFDatetimeCoder. Please add 'use_cftime' " - "when initializing xarray.coders.CFDatetimeCoder." + "CFDatetimeCoder. Please add 'use_cftime' " + "when initializing CFDatetimeCoder." ) var = decode_times.decode(var, name=name) @@ -325,9 +326,7 @@ def decode_cf_variables( attributes: T_Attrs, concat_characters: bool | Mapping[str, bool] = True, mask_and_scale: bool | Mapping[str, bool] = True, - decode_times: bool - | times.CFDatetimeCoder - | Mapping[str, bool | times.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 | Mapping[str, bool] | None = None, @@ -464,7 +463,7 @@ def decode_cf( obj: T_DatasetOrAbstractstore, concat_characters: bool = True, mask_and_scale: bool = True, - decode_times: bool | times.CFDatetimeCoder = True, + decode_times: bool | CFDatetimeCoder = True, decode_coords: bool | Literal["coordinates", "all"] = True, drop_variables: T_DropVariables = None, use_cftime: bool | None = None, @@ -483,7 +482,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 xr.coders.CFDatetimeCoder, optional + decode_times : bool or CFDatetimeCoder, optional Decode cf times (e.g., integers since "hours since 2000-01-01") to np.datetime64. decode_coords : bool or {"coordinates", "all"}, optional @@ -563,7 +562,7 @@ def cf_decoder( attributes: T_Attrs, concat_characters: bool = True, mask_and_scale: bool = True, - decode_times: bool | times.CFDatetimeCoder = True, + decode_times: bool | CFDatetimeCoder = True, ) -> tuple[T_Variables, T_Attrs]: """ Decode a set of CF encoded variables and attributes. @@ -580,7 +579,7 @@ def cf_decoder( mask_and_scale : bool Lazily scale (using scale_factor and add_offset) and mask (using _FillValue). - decode_times : bool | xr.coders.CFDatetimeCoder + decode_times : bool | CFDatetimeCoder Decode cf times ("hours since 2000-01-01") to np.datetime64. Returns