|
4 | 4 | from __future__ import annotations |
5 | 5 |
|
6 | 6 | import datetime as dt |
| 7 | +import warnings |
7 | 8 | from typing import Any, cast |
8 | 9 |
|
9 | 10 | import polars as pl |
@@ -132,6 +133,16 @@ def sqlalchemy_dtype(self, dialect: sa.Dialect) -> sa_TypeEngine: |
132 | 133 | def pyarrow_dtype(self) -> pa.DataType: |
133 | 134 | return pa.date32() |
134 | 135 |
|
| 136 | + @property |
| 137 | + def _python_type(self) -> Any: |
| 138 | + return dt.date |
| 139 | + |
| 140 | + def _pydantic_field_kwargs(self) -> dict[str, Any]: |
| 141 | + if self.resolution is not None: |
| 142 | + warnings.warn("Date resolution is not translated to a pydantic constraint.") |
| 143 | + |
| 144 | + return super()._pydantic_field_kwargs() |
| 145 | + |
135 | 146 | def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series: |
136 | 147 | return generator.sample_date( |
137 | 148 | n, |
@@ -261,6 +272,16 @@ def sqlalchemy_dtype(self, dialect: sa.Dialect) -> sa_TypeEngine: |
261 | 272 | def pyarrow_dtype(self) -> pa.DataType: |
262 | 273 | return pa.time64("ns") |
263 | 274 |
|
| 275 | + @property |
| 276 | + def _python_type(self) -> Any: |
| 277 | + return dt.time |
| 278 | + |
| 279 | + def _pydantic_field_kwargs(self) -> dict[str, Any]: |
| 280 | + if self.resolution is not None: |
| 281 | + warnings.warn("Time resolution is not translated to a pydantic constraint.") |
| 282 | + |
| 283 | + return super()._pydantic_field_kwargs() |
| 284 | + |
264 | 285 | def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series: |
265 | 286 | return generator.sample_time( |
266 | 287 | n, |
@@ -394,6 +415,22 @@ def pyarrow_dtype(self) -> pa.DataType: |
394 | 415 | ) |
395 | 416 | return pa.timestamp(self.time_unit, time_zone) |
396 | 417 |
|
| 418 | + @property |
| 419 | + def _python_type(self) -> Any: |
| 420 | + return dt.datetime |
| 421 | + |
| 422 | + def _pydantic_field_kwargs(self) -> dict[str, Any]: |
| 423 | + if self.resolution is not None: |
| 424 | + warnings.warn( |
| 425 | + "Datetime resolution is not translated to a pydantic constraint." |
| 426 | + ) |
| 427 | + if self.time_zone is not None: |
| 428 | + warnings.warn( |
| 429 | + "Datetime time zone is not translated to a pydantic constraint." |
| 430 | + ) |
| 431 | + |
| 432 | + return super()._pydantic_field_kwargs() |
| 433 | + |
397 | 434 | def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series: |
398 | 435 | return generator.sample_datetime( |
399 | 436 | n, |
@@ -531,6 +568,18 @@ def sqlalchemy_dtype(self, dialect: sa.Dialect) -> sa_TypeEngine: |
531 | 568 | def pyarrow_dtype(self) -> pa.DataType: |
532 | 569 | return pa.duration(self.time_unit) |
533 | 570 |
|
| 571 | + @property |
| 572 | + def _python_type(self) -> Any: |
| 573 | + return dt.timedelta |
| 574 | + |
| 575 | + def _pydantic_field_kwargs(self) -> dict[str, Any]: |
| 576 | + if self.resolution is not None: |
| 577 | + warnings.warn( |
| 578 | + "Duration resolution is not translated to a pydantic constraint." |
| 579 | + ) |
| 580 | + |
| 581 | + return super()._pydantic_field_kwargs() |
| 582 | + |
534 | 583 | def _sample_unchecked(self, generator: Generator, n: int) -> pl.Series: |
535 | 584 | # NOTE: If no duration is specified, we default to 100 years |
536 | 585 | return generator.sample_duration( |
|
0 commit comments