Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 3 additions & 15 deletions dataframely/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
from . import random
from ._filter import filter
from ._rule import rule
from ._typing import DataFrame, LazyFrame, Validation
from .collection import (
Collection,
CollectionMember,
deserialize_collection,
read_parquet_metadata_collection,
)
from ._typing import DataFrame, LazyFrame
from .collection import Collection, CollectionMember
from .columns import (
Any,
Array,
Expand Down Expand Up @@ -51,14 +46,13 @@
UInt64,
)
from .config import Config
from .exc import DeserializationError
from .filter_result import FailureInfo
from .functional import (
concat_collection_members,
require_relationship_one_to_at_least_one,
require_relationship_one_to_one,
)
from .schema import Schema, deserialize_schema, read_parquet_metadata_schema
from .schema import Schema

__all__ = [
"random",
Expand All @@ -68,16 +62,12 @@
"LazyFrame",
"Collection",
"CollectionMember",
"deserialize_collection",
"Config",
"FailureInfo",
"concat_collection_members",
"require_relationship_one_to_at_least_one",
"require_relationship_one_to_one",
"Schema",
"deserialize_schema",
"read_parquet_metadata_schema",
"read_parquet_metadata_collection",
"Any",
"Binary",
"Bool",
Expand Down Expand Up @@ -106,6 +96,4 @@
"List",
"Array",
"Object",
"Validation",
"DeserializationError",
]
27 changes: 1 addition & 26 deletions dataframely/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ def __getattr__(self, name: str) -> Any:
raise ValueError(f"Module '{self.module}' is not installed.")


# ------------------------------------ DELTALAKE ------------------------------------- #

try:
import deltalake
from deltalake import DeltaTable
except ImportError:
deltalake = _DummyModule("deltalake") # type: ignore

class DeltaTable: # type: ignore # noqa: N801
pass

# ------------------------------------ SQLALCHEMY ------------------------------------ #

try:
Expand Down Expand Up @@ -69,27 +58,13 @@ class Dialect: # type: ignore # noqa: N801
_polars_version_tuple = tuple(
int(part) if part.isdigit() else part for part in pl.__version__.split(".")
)
if _polars_version_tuple < (1, 36):
from polars._typing import ( # type: ignore[attr-defined,unused-ignore]
PartitioningScheme as PartitionSchemeOrSinkDirectory,
)
elif _polars_version_tuple < (1, 38): # pragma: no cover
from polars.io.partition import ( # type: ignore[no-redef,attr-defined,unused-ignore]
_SinkDirectory as PartitionSchemeOrSinkDirectory,
)
else:
from polars.io.partition import ( # type: ignore[no-redef,attr-defined,unused-ignore]
PartitionBy as PartitionSchemeOrSinkDirectory,
)

# ------------------------------------------------------------------------------------ #

__all__ = [
"deltalake",
"DeltaTable",
"Dialect",
"MSDialect_pyodbc",
"PartitionSchemeOrSinkDirectory",
"_polars_version_tuple",
"PGDialect_psycopg2",
"pydantic_core_schema",
"pydantic",
Expand Down
47 changes: 0 additions & 47 deletions dataframely/_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ def matches(self, other: Rule) -> bool:
"""
return self.expr.meta.eq(other.expr)

def as_dict(self) -> dict[str, Any]:
"""Turn the rule into a dictionary."""
return {"rule_type": self.__class__.__name__, "expr": self.expr}

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Self:
"""Read the rule from a dictionary.

Args:
data: The dictionary that was created via :meth:`asdict`.
"""
return cls(data["expr"])

def __repr__(self) -> str:
return str(self.expr)

Expand All @@ -81,13 +68,6 @@ def matches(self, other: Rule) -> bool:
return False
return super().matches(other) and self.group_columns == other.group_columns

def as_dict(self) -> dict[str, Any]:
return {**super().as_dict(), "group_columns": self.group_columns}

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Self:
return cls(data["expr"], group_columns=data["group_columns"])

def __repr__(self) -> str:
return f"{super().__repr__()} grouped by {self.group_columns}"

Expand Down Expand Up @@ -271,30 +251,3 @@ def _with_group_rules(lf: pl.LazyFrame, rules: dict[str, GroupRule]) -> pl.LazyF
frame, on=list(group_columns), nulls_equal=True, maintain_order="left"
)
return result


# ------------------------------------------------------------------------------------ #
# FACTORY #
# ------------------------------------------------------------------------------------ #

_TYPE_MAPPING: dict[str, type[Rule]] = {
Rule.__name__: Rule,
GroupRule.__name__: GroupRule,
}


def rule_from_dict(data: dict[str, Any]) -> Rule:
"""Dynamically read a rule object from a dictionary.

Args:
data: The dictionary obtained by calling :meth:`~Rule.asdict` on a rule object.
The dictionary must contain a key `"rule_type"` that indicates which rule
type to instantiate.

Returns:
The rule object as read from `data`.
"""
name = data["rule_type"]
if name not in _TYPE_MAPPING:
raise ValueError(f"Unknown rule type: {name}")
return _TYPE_MAPPING[name].from_dict(data)
118 changes: 0 additions & 118 deletions dataframely/_serialization.py

This file was deleted.

7 changes: 0 additions & 7 deletions dataframely/_storage/__init__.py

This file was deleted.

Loading