Skip to content

Commit

Permalink
Update to Data Package (v2) (#19)
Browse files Browse the repository at this point in the history
* Updated profiles

* Added `dialect.type` to the model

* Updatd `schema/field.missingValues`

* Added `categories/categoriesOrdered`

* Added metadata in table schema

* Commented out the properties that are not in v2 yet
  • Loading branch information
roll authored Jun 26, 2024
1 parent fb76eae commit c772df7
Show file tree
Hide file tree
Showing 12 changed files with 1,497 additions and 209 deletions.
5 changes: 5 additions & 0 deletions dplib/models/dialect/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class Dialect(Model):
)
"""A profile URL"""

# type: Optional[str] = None
"""
Type of the dialect e.g. "delimited"
"""

title: Optional[str] = None
"""
A string providing a title or one sentence description for this dialect
Expand Down
14 changes: 14 additions & 0 deletions dplib/models/field/categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import List, Optional, Union

from ...system import Model


class CategoryDict(Model):
value: str
label: Optional[str] = None


ICategories = Union[
List[str],
List[CategoryDict],
]
5 changes: 3 additions & 2 deletions dplib/models/field/datatypes/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

from typing import Any, List, Optional
from typing import Any, Optional

import pydantic

from .... import types
from ....system import Model
from ...missingValues import IMissingValues


class BaseField(Model):
Expand All @@ -32,7 +33,7 @@ class BaseField(Model):
A description for this field e.g. “The recipient of the funds”
"""

missingValues: List[str] = [""]
missingValues: IMissingValues = [""]
"""
A list of field values to consider as null values
"""
Expand Down
12 changes: 12 additions & 0 deletions dplib/models/field/datatypes/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pydantic

from ..categories import ICategories
from ..constraints import ValueConstraints
from .base import BaseField

Expand All @@ -15,6 +16,17 @@ class IntegerField(BaseField):
format: Optional[Literal["default"]] = None
constraints: ValueConstraints[int] = pydantic.Field(default_factory=ValueConstraints)

categories: Optional[ICategories] = None
"""
Property to restrict the field to a finite set of possible values
"""

categoriesOrdered: bool = False
"""
When categoriesOrdered is true, implementations SHOULD regard the order of
appearance of the values in the categories property as their natural order.
"""

groupChar: Optional[str] = None
"""
String whose value is used to group digits for integer/number fields
Expand Down
12 changes: 12 additions & 0 deletions dplib/models/field/datatypes/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pydantic

from ..categories import ICategories
from ..constraints import StringConstraints
from .base import BaseField

Expand All @@ -22,3 +23,14 @@ class StringField(BaseField):
type: Literal["string"] = "string"
format: Optional[IStringFormat] = None
constraints: StringConstraints = pydantic.Field(default_factory=StringConstraints)

categories: Optional[ICategories] = None
"""
Property to restrict the field to a finite set of possible values
"""

categoriesOrdered: bool = False
"""
When categoriesOrdered is true, implementations SHOULD regard the order of
appearance of the values in the categories property as their natural order.
"""
14 changes: 14 additions & 0 deletions dplib/models/missingValues.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import List, Optional, Union

from ..system import Model


class MissingValueDict(Model):
value: str
label: Optional[str] = None


IMissingValues = Union[
List[str],
List[MissingValueDict],
]
2 changes: 1 addition & 1 deletion dplib/models/schema/__spec__/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_schema_to_dict():
assert schema.to_dict() == {
"$schema": settings.PROFILE_CURRENT_SCHEMA,
}
schema.missingValues.append("x")
schema.missingValues.append("x") # type: ignore
assert schema.to_dict() == {
"$schema": settings.PROFILE_CURRENT_SCHEMA,
"missingValues": ["", "x"],
Expand Down
39 changes: 36 additions & 3 deletions dplib/models/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

from ... import settings, types
from ...system import Model

# from ..contributor import Contributor
from ..field import IField
from ..missingValues import IMissingValues
from .foreignKey import ForeignKey
from .types import IFieldsMatch

Expand All @@ -20,17 +23,47 @@ class Schema(Model):
)
"""A profile URL"""

title: Optional[str] = None
# name: Optional[str] = None
"""
A simple name or identifier as for Data Package
"""

# title: Optional[str] = None
"""
A string providing a title or one sentence description for this schema
"""

description: Optional[str] = None
# description: Optional[str] = None
"""
A description of the schema. The description MUST be markdown formatted —
this also allows for simple plain text as plain text is itself valid markdown.
"""

# homepage: Optional[str] = None
"""
A URL for the home on the web that is related to this data package.
"""

# keywords: List[str] = []
"""
The `keywords` property is a list of short keywords related to the schema.
"""

# examples: List[dict[str, str]] = []
"""
The `examples` property contains links to example data resources.
"""

# version: Optional[str] = None
"""
The `version` property stores the version of the schema
"""

# contributors: List[Contributor] = []
"""
The people or organizations who contributed to this Table Schema.
"""

fields: List[IField] = []
"""
List of fields in the table schema
Expand All @@ -42,7 +75,7 @@ class Schema(Model):
are defined by the fieldsMatch property.
"""

missingValues: List[str] = [""]
missingValues: IMissingValues = [""]
"""
A list of field values to consider as null values
"""
Expand Down
Loading

0 comments on commit c772df7

Please sign in to comment.