Skip to content

feat: Allow specifying Duration time unit#301

Merged
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
nardi:duration-time-unit
Mar 23, 2026
Merged

feat: Allow specifying Duration time unit#301
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
nardi:duration-time-unit

Conversation

@nardi
Copy link
Contributor

Motivation

I tried to use the library, but our data model requires Durations with a specific time unit. I saw this was implemented for Datetime but not for Duration, so I implemented it in an analogous way.

Changes

  1. Added time_unit attribute to dataframely.columns.datetime.Duration.
  2. Use time_unit when converting to Polars and Arrow data types.
  3. Use time_unit when generating samples.
  4. Add test for conversions to pyarrow schema, analogous to Datetime.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Dataframely’s Duration column type to support specifying a Polars/Arrow duration time_unit, analogous to the existing Datetime support, so schemas can precisely express and export duration precision.

Changes:

  • Add a time_unit attribute to dy.Duration and propagate it into Polars dtype and PyArrow dtype conversions.
  • Thread time_unit through duration sample generation so sampled series can be created with the requested duration unit.
  • Add a PyArrow schema test to confirm Duration(time_unit=...) exports as duration[<unit>].

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
dataframely/columns/datetime.py Adds time_unit support to the Duration column and uses it for Polars/Arrow dtype + sampling.
dataframely/random.py Extends Generator.sample_duration with a time_unit argument and casts sampled values accordingly.
tests/columns/test_pyarrow.py Adds coverage for Duration(time_unit=...) conversion to PyArrow schema.

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6e06c73) to head (ff3a9e9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #301   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         3217      3218    +1     
=========================================
+ Hits          3217      3218    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thanks!

@borchero Oliver Borchert (borchero) merged commit 72fb1a6 into Quantco:main Mar 23, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants