Skip to content

Commit

Permalink
chore: more misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brendancooley committed Oct 26, 2023
1 parent 97fbf5b commit 8e3b3f5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/patito/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from patito import exceptions, sql
from patito.polars import DataFrame, LazyFrame
from patito.pydantic import Field, Model
from patito.exceptions import DataFrameValidationError

_CACHING_AVAILABLE = False
_DUCKDB_AVAILABLE = False
field = col("_")
__all__ = [
"DataFrame",
"DataFrameValidationError",
"Expr",
"Field",
"LazyFrame",
Expand Down
3 changes: 0 additions & 3 deletions src/patito/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ def errors(self) -> List["ErrorDict"]:
self._error_cache = list(flatten_errors(self.raw_errors))
return self._error_cache

# def json(self, *, indent: Union[None, int, str] = 2) -> str:
# return json.dumps(self.errors(), indent=indent, default=pydantic_encoder)

def __str__(self) -> str:
errors = self.errors()
no_errors = len(errors)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_dummy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def test_generation_of_unique_data():

class UniqueModel(pt.Model):
bool_column: bool
string_column: str = pt.Field(json_schema_extra={"unique": True})
int_column: int = pt.Field(json_schema_extra={"unique": True})
float_column: int = pt.Field(json_schema_extra={"unique": True})
date_column: date = pt.Field(json_schema_extra={"unique": True})
datetime_column: datetime = pt.Field(json_schema_extra={"unique": True})
string_column: str = pt.Field(unique=True)
int_column: int = pt.Field(unique=True)
float_column: int = pt.Field(unique=True)
date_column: date = pt.Field(unique=True)
datetime_column: datetime = pt.Field(unique=True)

example_df = UniqueModel.examples({"bool_column": [True, False]})
for column in UniqueModel.columns:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class MyModel(pt.Model):

ExpandedModel = MyModel.with_fields(
b=(int, ...),
c=(int, None), # TODO should this be nullable if not specified as optional?
c=(int, None),
d=(int, pt.Field(gt=10)),
e=(Optional[int], None),
)
Expand Down
8 changes: 3 additions & 5 deletions tests/test_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ def test_correct_columns_and_dtype_on_read(tmp_path):
"""A model DataFrame should aid CSV reading with column names and dtypes."""

class Foo(pt.Model):
a: str = pt.Field(json_schema_extra={"derived_from": "column_1"})
b: int = pt.Field(json_schema_extra={"derived_from": "column_2"})
a: str = pt.Field(derived_from="column_1")
b: int = pt.Field(derived_from="column_2")

csv_path = tmp_path / "foo.csv"
csv_path.write_text("1,2")
Expand Down Expand Up @@ -189,9 +189,7 @@ class Foo(pt.Model):
assert unspecified_column_df.dtypes == [pl.Utf8, pl.Int64, pl.Float64]

class DerivedModel(pt.Model):
cents: int = pt.Field(
json_schema_extra={"derived_from": 100 * pl.col("dollars")}
)
cents: int = pt.Field(derived_from=100 * pl.col("dollars"))

csv_path.write_text("month,dollars\n1,2.99")
derived_df = DerivedModel.DataFrame.read_csv(csv_path)
Expand Down
5 changes: 2 additions & 3 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
import enum
import sys
from datetime import date, datetime
from typing import List, Optional, Union
from typing import List, Optional, Union, Literal

import polars as pl
import pytest
from typing_extensions import Literal

import patito as pt
from patito.exceptions import DataFrameValidationError
from patito import DataFrameValidationError
from patito.validators import _dewrap_optional, _is_optional, validate


Expand Down

0 comments on commit 8e3b3f5

Please sign in to comment.