Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table schema validator #125

Merged
merged 31 commits into from
Feb 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0f5f7db
:sparkles: Add column validator and associated classes.
dalonsoa Oct 23, 2024
17f94c3
Merge branch 'develop' into table_validator
dalonsoa Oct 24, 2024
cc2f4d3
:sparkles: Support python 3.9.
dalonsoa Oct 24, 2024
739792d
:sparkles: Support python 3.9, again.
dalonsoa Oct 24, 2024
f2d613a
Revert ":sparkles: Support python 3.9, again."
dalonsoa Oct 24, 2024
184a3ff
:heavy_plus_sign: Add extra pydantic helper dpeendency.
dalonsoa Oct 24, 2024
b4d3fad
:heavy_plus_sign: Add extra dependency.
dalonsoa Oct 24, 2024
73823fa
:sparkles: Add column validator and associated classes.
dalonsoa Oct 23, 2024
ad1c9ae
:sparkles: Support python 3.9.
dalonsoa Oct 24, 2024
801fdef
:sparkles: Support python 3.9, again.
dalonsoa Oct 24, 2024
cdd61cd
Revert ":sparkles: Support python 3.9, again."
dalonsoa Oct 24, 2024
7d93860
:heavy_plus_sign: Add extra pydantic helper dpeendency.
dalonsoa Oct 24, 2024
279586f
:heavy_plus_sign: Add extra dependency.
dalonsoa Oct 24, 2024
aff62f2
Fix messy rebasing.
dalonsoa Dec 19, 2024
d0bf9d2
:sparkles: Implement several type-specific validators.
dalonsoa Dec 19, 2024
e633ee1
:sparkles: Add BooleanColumnValidator
dalonsoa Dec 19, 2024
44488aa
:sparkles: Add DateTimeColumnValidator.
dalonsoa Dec 19, 2024
8113d43
:sparkles: Add the Geopoint and GeoJSON column validators.
dalonsoa Dec 19, 2024
4fae509
:sparkles: Add SchemaValidator.
dalonsoa Dec 19, 2024
051cd3e
:recycle: Split code in validators.py.
dalonsoa Dec 19, 2024
2c8f968
:rotating_light: Keep mypy happy.
dalonsoa Dec 19, 2024
1eb2069
Add pydantic plugin for mypy.
dalonsoa Dec 19, 2024
6fb61e1
:white_check_mark: Add tests for the table validator classes.
dalonsoa Dec 19, 2024
3a69368
:recycle: Move file.
dalonsoa Dec 19, 2024
2f845c8
Merge branch 'main' into table_validator
dalonsoa Dec 19, 2024
51272b7
:arrow_up: Drop support for Python 3.9 and add for Python 3.13
dalonsoa Dec 19, 2024
cb148bf
Merge pull request #169 from ImperialCollegeLondon/drop-py-39
dalonsoa Dec 19, 2024
7a5a807
Merge branch 'table_validator' of https://github.com/ImperialCollegeL…
dalonsoa Feb 7, 2025
ab9e873
:wrench: Update lock file.
dalonsoa Feb 7, 2025
ad9e960
:recycle: Add reviwers comments.
dalonsoa Feb 7, 2025
c82f2c0
Merge branch 'main' into table_validator
dalonsoa Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Add DateTimeColumnValidator.
dalonsoa committed Dec 19, 2024
commit 44488aa540409b5dd4f6baa9d85e6555064e8922
44 changes: 43 additions & 1 deletion csvy/validators.py
Original file line number Diff line number Diff line change
@@ -269,6 +269,20 @@ class FormatString(str, Enum):
UUID = "uuid"


class FormatDateTime(str, Enum):
"""Enumeration of the formats for the Table Schema for the datetime type.
default: Declares that the datetime objects follows the ISO8601 format.
- datetime: YYYY-MM-DD
- time: hh:mm:ss in 24-hour time and UTC timezone.
- datetime: YYYY-MM-DDThh:mm:ssZ in 24-hour time and UTC timezone.
any: Any parsable datetime format.
"""

DEFAULT = "default"
ANY = "any"


class ConstraintsValidator(BaseModel):
"""Validator for the constraints in the Table Schema.
@@ -511,11 +525,39 @@ class BooleanColumnValidator(CommonValidator):
)


class DateTimeColumnValidator(CommonValidator):
"""Validator for the datetime columns in the Table Schema.
This class is used to validate the datetime columns in the Table Schema. It is based
on the columns defined in the Table Schema specification.
Attributes:
type_: A string specifying the type, with valid values being 'datetime'.
format_: A string specifying a format. It can be 'default' or 'any', or a string
with a custom format parsable by Python / C standard 'strptime', eg.
'%d/%m/%y'.
"""

type_: Literal[TypeEnum.DATETIME, TypeEnum.DATE, TypeEnum.TIME] = Field(
TypeEnum.DATETIME, alias="type", description="A string specifying the type."
)
format_: FormatDateTime | str | None = Field(
None,
alias="format",
description="A string specifying a format. It can be "
+ "'default' or 'any', or a string with a custom format parsable by Python / C "
+ "standard 'strptime', eg. '%d/%m/%y'.",
)


ColumnValidator = Annotated[
DefaultColumnValidator
| StringColumnValidator
| NumberColumnValidator
| IntegerColumnValidator,
| IntegerColumnValidator
| BooleanColumnValidator
| DateTimeColumnValidator,
Field(discriminator="type_"),
]
"""Annotated type for the ColumnValidator."""