Table of Contents

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 common_instance(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, type 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

bool

Methods

Descr(DatetimeMetaData)

NumPy's create_datetime_dtype: a native descriptor of this class carrying meta.

public DType Descr(DatetimeMetaData meta)

Parameters

meta DatetimeMetaData

The unit and multiplier the descriptor carries.

Returns

DType

A fresh native descriptor (isbuiltin == 0, as every NumPy datetime descriptor).

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

unit NPY_DATETIMEUNIT

The unit.

Returns

DType

A fresh native descriptor.

common_dtype(DTypeMeta)

NumPy's datetime_common_dtype: datetime absorbs timedelta; otherwise the builtin rule.

public override DTypeMeta common_dtype(DTypeMeta other)

Parameters

other DTypeMeta

The other operand's class.

Returns

DTypeMeta

The common class, or null (NotImplemented) when the builtin rule defers to other.

Exceptions

ArgumentNullException

other is null.

common_instance(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 common_instance(DType descr1, DType descr2)

Parameters

descr1 DType

The first descriptor, a datetime64 or timedelta64 one.

descr2 DType

The second descriptor, a datetime64 or timedelta64 one.

Returns

DType

A fresh native descriptor carrying the unit GCD.

Exceptions

ArgumentNullException

Either descriptor is null.

TypeError

Either descriptor is not a datetime64 / timedelta64 one, or the units have no common divisor (a timedelta years/months unit against a time unit: NumPy's "Cannot get a common metadata divisor …" text).

OverflowError

The common divisor overflows (NumPy's "Integer overflow getting a common metadata divisor …").

default_descr()

NumPy's datetime_and_timedelta_default_descr: a fresh generic-unit descriptor (NumPy copies the singleton, so np.dtype('M8').isbuiltin is 0).

public override DType default_descr()

Returns

DType

A fresh native generic-unit descriptor.

ensure_canonical(DType)

NumPy's ensure_native_byteorder (the datetime pair shares the legacy slot): the descriptor itself when native, else a native copy keeping its unit and metadata.

public override DType ensure_canonical(DType descr)

Parameters

descr DType

A descriptor of THIS class.

Returns

DType

descr when native, else a fresh copy with byte order '='.

Exceptions

ArgumentNullException

descr is null.

ArgumentException

descr belongs to another class.