pycontrails.utils.types¶
Convienence types.
Module Attributes
Datetime like input (datetime, pd.Timestamp, np.datetime64) |
Functions
|
Apply |
|
Shortcut utility to type guard a variable with custom error message. |
- type pycontrails.utils.types.DatetimeLike = datetime | Timestamp | datetime64 | str¶
Datetime like input (datetime, pd.Timestamp, np.datetime64)
- pycontrails.utils.types.apply_nan_mask_to_arraylike[T: (ndarray, DataArray)](arr, nan_mask)¶
Apply
nan_masktoarrwhile maintaining the type.The parameter
arrshould have afloatdtype.This function is tested against
DataArray,Series, andndarraytypes.- Parameters:
nan_mask (
numpy.ndarray) – Boolean array of the same shape asarr
- Returns:
T– Arrayarrwith values innan_maskset tonp.nan. Thearris mutated in place if it is andarray. ForDataArray, a copy is returned.
Notes
When
arris aDataArray, this function keeps anyattrsfromarrin the returned instance.
- pycontrails.utils.types.type_guard[T](obj, type_, error_message=None)¶
Shortcut utility to type guard a variable with custom error message.
- Parameters:
obj (
Any) – Any variable objecttype_ (
type[T] | tuple[type[T],]) – Type of variable. Can be a tuple of typeserror_message (
str, optional) – Custom error message
- Returns:
T– Returns the input object ensured to betype_- Raises:
ValueError – Raises ValueError if
objis nottype_