@@ -440,6 +440,7 @@ def __init__(
440440 max : dt .timedelta | None = None ,
441441 max_exclusive : dt .timedelta | None = None ,
442442 resolution : str | None = None ,
443+ time_unit : TimeUnit = "us" ,
443444 check : Check | None = None ,
444445 alias : str | None = None ,
445446 metadata : dict [str , Any ] | None = None ,
@@ -462,6 +463,7 @@ def __init__(
462463 the formatting language used by :mod:`polars` datetime `truncate` method.
463464 For example, a value `1h` expects all durations to be full hours. Note
464465 that this setting does *not* affect the storage resolution.
466+ time_unit: Unit of time. Defaults to `us` (microseconds).
465467 check: A custom rule or multiple rules to run for this column. This can be:
466468 - A single callable that returns a non-aggregated boolean expression.
467469 The name of the rule is derived from the callable name, or defaults to
@@ -504,10 +506,11 @@ def __init__(
504506 metadata = metadata ,
505507 )
506508 self .resolution = resolution
509+ self .time_unit = time_unit
507510
508511 @property
509512 def dtype (self ) -> pl .DataType :
510- return pl .Duration ()
513+ return pl .Duration (time_unit = self . time_unit )
511514
512515 def validation_rules (self , expr : pl .Expr ) -> dict [str , pl .Expr ]:
513516 result = super ().validation_rules (expr )
@@ -526,7 +529,7 @@ def sqlalchemy_dtype(self, dialect: sa.Dialect) -> sa_TypeEngine:
526529
527530 @property
528531 def pyarrow_dtype (self ) -> pa .DataType :
529- return pa .duration ("us" )
532+ return pa .duration (self . time_unit )
530533
531534 def _sample_unchecked (self , generator : Generator , n : int ) -> pl .Series :
532535 # NOTE: If no duration is specified, we default to 100 years
@@ -543,6 +546,7 @@ def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series:
543546 default = dt .timedelta (days = 365 * 100 ),
544547 ),
545548 resolution = self .resolution ,
549+ time_unit = self .time_unit ,
546550 null_probability = self ._null_probability ,
547551 )
548552
0 commit comments