Skip to content

Un-enterable time unit conversion block #614

@trexfeathers

Description

@trexfeathers

This block:

cf-units/cf_units/__init__.py

Lines 1731 to 1744 in 23bd604

# Use cftime for converting reference times that are not using a
# gregorian calendar as it handles these and udunits does not.
if self.is_time_reference() and self.calendar != CALENDAR_STANDARD:
result_datetimes = cftime.num2date(
result, self.cftime_unit, self.calendar
)
result = cftime.date2num(
result_datetimes, other.cftime_unit, other.calendar
)
convert_type = isinstance(value, np.ndarray) and np.issubdtype(
value.dtype, np.floating
)
if convert_type:
result = result.astype(value.dtype)

... will never be entered because it is hidden behind this check:

if self.is_convertible(other):

cf-units/cf_units/__init__.py

Lines 998 to 1002 in 23bd604

else:
result = self.calendar == other.calendar and _ud.are_convertible(
self.ut_unit, other.ut_unit
)
return result


This may be inconsequential given these docs, but in either case this block should presumably be removed?

cf-units/cf_units/__init__.py

Lines 1709 to 1718 in 23bd604

.. note::
Conversion between unit calendars is not permitted unless the
calendars are aliases, see :attr:`cf_units.CALENDAR_ALIASES`.
>>> from cf_units import Unit
>>> a = Unit('days since 1850-1-1', calendar='gregorian')
>>> b = Unit('days since 1851-1-1', calendar='standard')
>>> a.convert(365.75, b)
0.75

Metadata

Metadata

Assignees

No one assigned

    Labels

    New: IssueHighlight a new community raised "generic" issueType: Bug

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions