Class DatetimeDTypeMeta
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The DType classes of datetime64 (np.dtypes.DateTime64DType, type number 21, kind/char
'M') and timedelta64 (np.dtypes.TimeDelta64DType, 22, 'm') — NumSharp's first
PARAMETRIC classes: the unit metadata (DatetimeMetaData) lives on the descriptor INSTANCE, so
M8[ns] and M8[s] are two descriptors of one class, and promotion runs
CommonInstance(DType, DType) (the unit GCD) instead of returning a class default.
public sealed class DatetimeDTypeMeta : DTypeMeta
- Inheritance
-
DatetimeDTypeMeta
- Inherited Members
Remarks
Stage A is DESCRIPTOR-level: parsing (np.dtype("M8[10ns]")), formatting, equality,
np.datetime_data, GCD promotion and the unit casting rules. The class has no storage yet
(TypeCode is Empty, ScalarType is
null); allocating an array with a datetime descriptor raises NotSupportedException. Stage C adds
the int64 storage lane, NaT, ISO-8601 and the arithmetic loops (docs/plans/datetime64.md).
The slots are NumPy's (dtypemeta.c): default_descr hands out a COPY of the generic-unit
descriptor (NumPy's datetime_and_timedelta_default_descr — which is why np.dtype('M8').isbuiltin is
0), common_dtype is datetime_common_dtype (datetime absorbs timedelta; then the builtin table,
which lets timedelta absorb bool and the integers narrower than uint64 and refuses everything else), and
common_instance is datetime_type_promotion (the metadata GCD, strict about the non-linear
years/months for timedelta operands and relaxed for datetime ones).
Properties
IsTimedelta
True for timedelta64 (a duration), false for datetime64 (a moment).
public bool IsTimedelta { get; }
Property Value
Methods
CommonDType(DTypeMeta)
NumPy's datetime_common_dtype: datetime absorbs timedelta; otherwise the builtin rule.
public override DTypeMeta CommonDType(DTypeMeta other)
Parameters
otherDTypeMeta
Returns
CommonInstance(DType, DType)
NumPy's datetime_type_promotion: the result is datetime64 if either operand is one, else
timedelta64, with the metadata GCD — strict about years/months for a timedelta operand, relaxed for
a datetime one. (By the time this runs, PromoteTypes(DType, DType) has already cast both
operands to THIS class — a timedelta cast to datetime keeps its unit but loses the strictness, which is why
promote_types('m8[Y]', 'M8[D]') is M8[D] while promote_types('m8[Y]', 'm8[D]') raises.)
public override DType CommonInstance(DType descr1, DType descr2)
Parameters
Returns
DefaultDescr()
A fresh generic-unit descriptor (NumPy's datetime_and_timedelta_default_descr copies the singleton).
public override DType DefaultDescr()
Returns
Descr(DatetimeMetaData)
NumPy's create_datetime_dtype: a native descriptor of this class carrying meta.
public DType Descr(DatetimeMetaData meta)
Parameters
metaDatetimeMetaData
Returns
Descr(NPY_DATETIMEUNIT)
NumPy's create_datetime_dtype_with_unit: a native descriptor with unit unit and multiplier 1.
public DType Descr(NPY_DATETIMEUNIT unit)
Parameters
unitNPY_DATETIMEUNIT
Returns
EnsureCanonical(DType)
ensure_canonical: the native-byte-order form of descr (the descriptor itself when
already native).
public override DType EnsureCanonical(DType descr)
Parameters
descrDType