Skip to content

DatePart(unit) Source

Bases: TimeFunction

A part of each date, datetime or time of day, as a number: its month, its day of the week, its hour...

The result is a FLOAT64 Array, so a missing date gives a missing part. Every January of every year gives 1: use DatePeriod to tell January 2026 from January 2027.

Added in version 0.1.0

Parameters:

Raises:

Examples:

from datetime import date
import numdaplot as ndp

days = ndp.Array.from_list([date(2026, 1, 5), None, date(2027, 1, 9)])
days.apply(ndp.DatePart(unit=ndp.DatePartUnit.MONTH))
# Array([ 1., nan,  1.], dtype=FLOAT64)
days.apply(ndp.DatePart(unit=ndp.DatePartUnit.WEEKDAY))
# Array([ 1., nan,  6.], dtype=FLOAT64)