You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turn date strings into cyclical encodings your model can actually learn from.
📋 Overview
A date is a string until you encode it. KDP parses the column, splits it into year, month, day of month and day of week, and encodes each one cyclically — as a sine/cosine pair — so December and January sit next to each other rather than at opposite ends of a number line. Optionally it adds a one-hot season.
fromkdpimportPreprocessingModelfromkdp.featuresimportDateFeature, FeatureTypepreprocessor=PreprocessingModel(
path_data="data.csv",
features_specs={
"signup_date": DateFeature(
name="signup_date",
feature_type=FeatureType.DATE,
format="YYYY-MM-DD", # or "YYYY/MM/DD", each with an optional timeadd_season=True, # append a 4-dim one-hot season
),
},
)
preprocessor.build_preprocessor()
⚙️ Configuration Parameters
DateFeature takes exactly two options. Anything else you pass is accepted
and not used, and says so in a warning.
Parameter
Type
Default
Description
format
str
"YYYY-MM-DD"
Layout of the date string. Dates are read as year, then month, then day, separated by - or /, and may be followed by a time -- "%Y-%m-%d", "%Y/%m/%d", "%Y-%m-%d %H:%M:%S" and "YYYY-MM-DD" all describe a column this reads. A day-first or month-first format is refused where you write it. date_format is accepted as a synonym.
add_season
bool
False
Append a 4-dimensional one-hot season vector to the encoding.
!!! warning "Other date options do not exist"
Earlier documentation listed options such as add_year, add_month,
add_day_of_week, add_hour, add_is_weekend, add_quarter,
cyclical_encoding, add_time_since_reference, reference_date and
time_since_unit. None of them are read by KDP. DateFeature accepts
arbitrary keyword arguments, and only output_format and extract are
called out in a warning; the rest pass without a word and change nothing.
Year, month, day of month and day
of week are always extracted and always cyclically encoded; that
is not configurable. For anything beyond that, use a
custom preprocessing pipeline.
📐 What You Actually Get
Each date column expands to a fixed-width block of floats:
Configuration
Output width
Components
Default
8
year, month, day of month, day of week — each as a (sin, cos) pair
Month 12 and month 1 are one step apart in reality but eleven apart as
integers. Encoding each component as (sin, cos) places them adjacent on a
circle, so a model can learn "end of year rolls into start of year" without
having to memorise the discontinuity.
🔗 Combining With Other Features
Feature selection
Date features participate in learned feature selection:
Need hour-of-day, a weekend flag, or days since a reference date? Those are
not built in. Supply your own layers with preprocessors, which receives the
raw string column:
A DATE feature encodes one timestamp per row, independently. If you need
lags, rolling statistics or differencing across ordered rows, that is a
Time Series Feature — where a date column
serves as the sort_by key rather than as a feature itself.
💡 Practical Notes
Keep dates as strings in your CSV
KDP parses the string itself. Pre-converting to epoch integers turns the column numeric and skips date handling entirely.
Match the format exactly
Only YYYY-MM-DD and YYYY/MM/DD parse. Normalise other layouts before writing the CSV.
add_season is cheap
Four extra dimensions, no statistics needed. Worth enabling when seasonality plausibly matters.
Dates need no statistics pass
The encoding is deterministic, so nothing is learned from your data for this column.