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
12 changes: 0 additions & 12 deletions dataframely/_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: BSD-3-Clause

import os
import warnings
from collections.abc import Callable
from functools import wraps

Expand All @@ -26,14 +25,3 @@ def wrapper() -> None:
return wrapper

return decorator


@skip_if(env="DATAFRAMELY_NO_FUTURE_WARNINGS")
def warn_nullable_default_change() -> None:
warnings.warn(
"The 'nullable' argument was not explicitly set. In a future release, "
"'nullable=False' will be the default if 'nullable' is not specified. "
"Explicitly set 'nullable=True' if you want your column to be nullable.",
FutureWarning,
stacklevel=4,
)
14 changes: 1 addition & 13 deletions dataframely/columns/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import polars as pl

from dataframely._compat import pa, sa, sa_TypeEngine
from dataframely._deprecation import (
warn_nullable_default_change,
)
from dataframely._polars import PolarsDataType
from dataframely.random import Generator

Expand Down Expand Up @@ -45,7 +42,7 @@ class Column(ABC):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
check: Check | None = None,
alias: str | None = None,
Expand All @@ -55,8 +52,6 @@ def __init__(
Args:
nullable: Whether this column may contain null values.
Explicitly set `nullable=True` if you want your column to be nullable.
In a future release, `nullable=False` will be the default if `nullable`
is not specified.
primary_key: Whether this column is part of the primary key of the schema.
If ``True``, ``nullable`` is automatically set to ``False``.
check: A custom rule or multiple rules to run for this column. This can be:
Expand All @@ -80,13 +75,6 @@ def __init__(
if nullable and primary_key:
raise ValueError("Nullable primary key columns are not supported.")

if nullable is None:
if primary_key:
nullable = False
else:
warn_nullable_default_change()
nullable = True

self.nullable = nullable
self.primary_key = primary_key
self.check = check
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Categorical(Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
check: Check | None = None,
alias: str | None = None,
Expand Down
8 changes: 4 additions & 4 deletions dataframely/columns/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Date(OrdinalMixin[dt.date], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: dt.date | None = None,
min_exclusive: dt.date | None = None,
Expand Down Expand Up @@ -157,7 +157,7 @@ class Time(OrdinalMixin[dt.time], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: dt.time | None = None,
min_exclusive: dt.time | None = None,
Expand Down Expand Up @@ -286,7 +286,7 @@ class Datetime(OrdinalMixin[dt.datetime], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: dt.datetime | None = None,
min_exclusive: dt.datetime | None = None,
Expand Down Expand Up @@ -433,7 +433,7 @@ class Duration(OrdinalMixin[dt.timedelta], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: dt.timedelta | None = None,
min_exclusive: dt.timedelta | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
precision: int | None = None,
scale: int = 0,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: decimal.Decimal | None = None,
min_exclusive: decimal.Decimal | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
self,
categories: pl.Series | Iterable[str] | type[enum.Enum],
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
check: Check | None = None,
alias: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _BaseFloat(OrdinalMixin[float], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
allow_inf_nan: bool = False,
min: float | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _BaseInteger(IsInMixin[int], OrdinalMixin[int], Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min: int | None = None,
min_exclusive: int | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self,
inner: Column,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
check: Check | None = None,
alias: str | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class String(Column):
def __init__(
self,
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
min_length: int | None = None,
max_length: int | None = None,
Expand Down
2 changes: 1 addition & 1 deletion dataframely/columns/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __init__(
self,
inner: dict[str, Column],
*,
nullable: bool | None = None,
nullable: bool = False,
primary_key: bool = False,
check: Check | None = None,
alias: str | None = None,
Expand Down
40 changes: 22 additions & 18 deletions tests/column_types/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@pytest.mark.parametrize(
"inner",
[
(dy.Int64()),
(dy.Integer()),
(dy.Int64(nullable=True)),
(dy.Integer(nullable=True)),
],
)
def test_integer_array(inner: Column) -> None:
Expand All @@ -29,12 +29,12 @@ def test_integer_array(inner: Column) -> None:


def test_invalid_inner_type() -> None:
schema = create_schema("test", {"a": dy.Array(dy.Int64(), 1)})
schema = create_schema("test", {"a": dy.Array(dy.Int64(nullable=True), 1)})
assert not schema.is_valid(pl.DataFrame({"a": [["1"], ["2"], ["3"]]}))


def test_invalid_shape() -> None:
schema = create_schema("test", {"a": dy.Array(dy.Int64(), 2)})
schema = create_schema("test", {"a": dy.Array(dy.Int64(nullable=True), 2)})
assert not schema.is_valid(
pl.DataFrame(
{"a": [[1], [2], [3]]},
Expand All @@ -49,52 +49,52 @@ def test_invalid_shape() -> None:
("column", "dtype", "is_valid"),
[
(
dy.Array(dy.Int64(), 1),
dy.Array(dy.Int64(nullable=True), 1),
pl.Array(pl.Int64(), 1),
True,
),
(
dy.Array(dy.String(), 1),
dy.Array(dy.String(nullable=True), 1),
pl.Array(pl.Int64(), 1),
False,
),
(
dy.Array(dy.String(), 1),
dy.Array(dy.String(nullable=True), 1),
pl.Array(pl.Int64(), 2),
False,
),
(
dy.Array(dy.Int64(), (1,)),
dy.Array(dy.Int64(nullable=True), (1,)),
pl.Array(pl.Int64(), (1,)),
True,
),
(
dy.Array(dy.Int64(), (1,)),
dy.Array(dy.Int64(nullable=True), (1,)),
pl.Array(pl.Int64(), (2,)),
False,
),
(
dy.Array(dy.String(), 1),
dy.Array(dy.String(), 1),
dy.Array(dy.String(nullable=True), 1),
dy.Array(dy.String(nullable=True), 1),
False,
),
(
dy.Array(dy.String(), 1),
dy.Array(dy.String(nullable=True), 1),
dy.String(),
False,
),
(
dy.Array(dy.String(), 1),
dy.Array(dy.String(nullable=True), 1),
pl.String(),
False,
),
(
dy.Array(dy.Array(dy.String(), 1), 1),
dy.Array(dy.Array(dy.String(nullable=True), 1), 1),
pl.Array(pl.String(), (1, 1)),
True,
),
(
dy.Array(dy.String(), (1, 1)),
dy.Array(dy.String(nullable=True), (1, 1)),
pl.Array(pl.Array(pl.String(), 1), 1),
True,
),
Expand All @@ -105,7 +105,9 @@ def test_validate_dtype(column: Column, dtype: pl.DataType, is_valid: bool) -> N


def test_nested_arrays() -> None:
schema = create_schema("test", {"a": dy.Array(dy.Array(dy.Int64(), 1), 1)})
schema = create_schema(
"test", {"a": dy.Array(dy.Array(dy.Int64(nullable=True), 1), 1)}
)
assert schema.is_valid(
pl.DataFrame(
{"a": [[[1]], [[2]], [[3]]]},
Expand All @@ -117,7 +119,9 @@ def test_nested_arrays() -> None:


def test_nested_array() -> None:
schema = create_schema("test", {"a": dy.Array(dy.Array(dy.Int64(), 1), 1)})
schema = create_schema(
"test", {"a": dy.Array(dy.Array(dy.Int64(nullable=True), 1), 1)}
)
assert schema.is_valid(
pl.DataFrame(
{"a": [[[1]], [[2]], [[3]]]},
Expand Down Expand Up @@ -147,7 +151,7 @@ def test_array_with_rules() -> None:
def test_outer_nullability() -> None:
schema = create_schema(
"test",
{"nullable": dy.Array(inner=dy.Integer(), shape=1, nullable=True)},
{"nullable": dy.Array(inner=dy.Integer(nullable=True), shape=1, nullable=True)},
)
df = pl.DataFrame({"nullable": [None, None]})
schema.validate(df, cast=True)
Loading
Loading