Skip to content

Commit

Permalink
refactor(schema): remove deprecated Schema.from_dict(), .delete()
Browse files Browse the repository at this point in the history
… and `.append()` methods

BREAKING CHANGE: `Schema.from_dict()`, `.delete()` and `.append()` methods are removed
  • Loading branch information
kszucs committed Jan 30, 2023
1 parent 6668122 commit 8912b24
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 104 deletions.
1 change: 0 additions & 1 deletion ibis/expr/datatypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
map_to,
validator,
)
from ibis.util import deprecated, warn_deprecated

dtype = Dispatcher('dtype')

Expand Down
93 changes: 2 additions & 91 deletions ibis/expr/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import collections
from typing import TYPE_CHECKING, Iterable, Iterator, Mapping
from typing import TYPE_CHECKING, Iterable, Iterator

from multipledispatch import Dispatcher

Expand All @@ -10,7 +10,7 @@
from ibis.common.exceptions import IntegrityError
from ibis.common.grounds import Concrete
from ibis.common.validators import frozendict_of, instance_of, validator
from ibis.util import deprecated, indent, warn_deprecated
from ibis.util import indent

if TYPE_CHECKING:
import pandas as pd
Expand Down Expand Up @@ -50,30 +50,6 @@ class Schema(Concrete):
"""A mapping of [`str`][str] to [`DataType`][ibis.expr.datatypes.DataType] objects
representing the type of each column."""

@classmethod
def __create__(cls, names, types=None):
if types is None:
return super().__create__(fields=names)
else:
warn_deprecated(
"Schema(names, types)",
as_of="4.1",
removed_in="5.0",
instead=(
"construct a Schema using a mapping of names to types instead: "
"Schema(dict(zip(names, types)))"
),
)
return schema(names, types)

def __reduce__(self):
return (self.__class__, (self.fields, None))

def copy(self, fields=None):
if fields is None:
fields = self.fields
return type(self)(fields)

def __repr__(self) -> str:
space = 2 + max(map(len, self.names), default=0)
return "ibis.Schema {{{}\n}}".format(
Expand Down Expand Up @@ -133,37 +109,6 @@ def equals(self, other: Schema) -> bool:
)
return self.__cached_equals__(other)

@deprecated(
as_of="4.1",
removed_in="5.0",
instead="construct a new Schema without the undesired names instead",
)
def delete(self, names_to_delete: Iterable[str]) -> Schema:
"""Remove `names_to_delete` names from `self`.
Parameters
----------
names_to_delete
Iterable of `str` to remove from the schema.
Examples
--------
>>> import ibis
>>> sch = ibis.schema({"a": "int", "b": "string"})
>>> sch.delete({"a"})
ibis.Schema {
b string
}
"""
for name in names_to_delete:
if name not in self:
raise KeyError(name)

delete = frozenset(names_to_delete)
fields = {k: v for k, v in self.fields.items() if k not in delete}

return self.__class__(fields)

@classmethod
def from_tuples(
cls,
Expand Down Expand Up @@ -192,36 +137,6 @@ def from_tuples(
"""
return cls(dict(values))

@classmethod
@deprecated(
as_of="4.1",
removed_in="5.0",
instead="directly construct a Schema instead",
)
def from_dict(cls, dictionary: Mapping[str, str | dt.DataType]) -> Schema:
"""Construct a `Schema` from a `Mapping`.
Parameters
----------
dictionary
Mapping from which to construct a `Schema` instance.
Returns
-------
Schema
A new schema
Examples
--------
>>> import ibis
>>> ibis.Schema.from_dict({"a": "int", "b": "string"})
ibis.Schema {
a int64
b string
}
"""
return cls(dictionary)

def to_pandas(self):
"""Return the equivalent pandas datatypes."""
from ibis.backends.pandas.client import ibis_schema_to_pandas
Expand All @@ -245,10 +160,6 @@ def __ge__(self, other: Schema) -> bool:
"""Return whether `self` is a superset of or equal to `other`."""
return set(self.items()) >= set(other.items())

@deprecated(as_of="4.1", removed_in="5.0", instead="use Schema.merge() instead")
def append(self, other: Schema) -> Schema:
return self.merge(other)

def merge(self, other: Schema) -> Schema:
"""Merge `other` to `self`.
Expand Down
15 changes: 3 additions & 12 deletions ibis/tests/expr/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ def test_whole_schema():


def test_schema_names_and_types_length_must_match():
with pytest.raises(IntegrityError), pytest.warns(FutureWarning):
sch.Schema(names=["a", "b"], types=["int", "str", "float"])
with pytest.raises(IntegrityError):
sch.schema(["a", "b"], ["int", "str", "float"])

with pytest.warns(FutureWarning):
schema = sch.Schema(names=["a", "b"], types=["int", "str"])
schema = sch.schema(["a", "b"], ["int", "str"])

assert isinstance(schema, sch.Schema)
assert schema.names == ("a", "b")
Expand Down Expand Up @@ -213,11 +212,3 @@ def test_api_accepts_schema_objects():
def test_names_types():
s = ibis.schema(names=["a"], types=["array<float64>"])
assert s == ibis.schema(dict(a="array<float64>"))


def test_schema_delete():
s1 = ibis.schema({"a": "int64", "b": "string", "c": "float64", "d": "int64"})
with pytest.warns(FutureWarning):
s2 = s1.delete(["b", "d"])

assert s2 == ibis.schema({"a": "int64", "c": "float64"})

0 comments on commit 8912b24

Please sign in to comment.