feat: Allow specifying Duration time unit#301
Merged
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom Mar 23, 2026
Merged
feat: Allow specifying Duration time unit#301Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
Oliver Borchert (borchero) merged 1 commit intoQuantco:mainfrom
Conversation
There was a problem hiding this comment.
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_unitattribute tody.Durationand propagate it into Polars dtype and PyArrow dtype conversions. - Thread
time_unitthrough 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 asduration[<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. |
352c7a6 to
ff3a9e9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Oliver Borchert (borchero)
approved these changes
Mar 23, 2026
Member
Oliver Borchert (borchero)
left a comment
There was a problem hiding this comment.
Lgtm, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I tried to use the library, but our data model requires
Durations with a specific time unit. I saw this was implemented forDatetimebut not forDuration, so I implemented it in an analogous way.Changes
time_unitattribute todataframely.columns.datetime.Duration.time_unitwhen converting to Polars and Arrow data types.time_unitwhen generating samples.pyarrowschema, analogous toDatetime.