Skip to content

Commit

Permalink
fix: define to_pandas/to_pyarrow on DataType/Schema classes directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist authored and gforsyth committed Nov 16, 2022
1 parent 24225ca commit 22f3b4d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 0 additions & 4 deletions ibis/backends/pandas/client.py
Expand Up @@ -308,10 +308,6 @@ def try_json(x):
return pd.Series(list(map(try_json, col)), dtype="object")


dt.DataType.to_pandas = ibis_dtype_to_pandas # type: ignore
sch.Schema.to_pandas = ibis_schema_to_pandas # type: ignore


class DataFrameProxy(Immutable, util.ToFrame):
__slots__ = ('_df', '_hash')

Expand Down
4 changes: 0 additions & 4 deletions ibis/backends/pyarrow/datatypes.py
Expand Up @@ -138,7 +138,3 @@ def ibis_to_pyarrow_struct(schema: sch.Schema) -> pa.StructType:

def ibis_to_pyarrow_schema(schema: sch.Schema) -> pa.Schema:
return pa.schema(_schema_to_pyarrow_schema_fields(schema))


dt.DataType.to_pyarrow = to_pyarrow_type # type: ignore
sch.Schema.to_pyarrow = ibis_to_pyarrow_schema # type: ignore
12 changes: 12 additions & 0 deletions ibis/expr/datatypes/core.py
Expand Up @@ -78,6 +78,18 @@ def castable(self, other, **kwargs):

return castable(self, other, **kwargs)

def to_pandas(self):
"""Return the equivalent pandas datatype."""
from ibis.backends.pandas.client import ibis_dtype_to_pandas

return ibis_dtype_to_pandas(self)

def to_pyarrow(self):
"""Return the equivalent pyarrow datatype."""
from ibis.backends.pyarrow.datatypes import to_pyarrow_type

return to_pyarrow_type(self)

def is_array(self) -> bool:
return isinstance(self, Array)

Expand Down
12 changes: 12 additions & 0 deletions ibis/expr/schema.py
Expand Up @@ -197,6 +197,18 @@ def from_dict(cls, dictionary: Mapping[str, str | dt.DataType]) -> Schema:
names, types = zip(*dictionary.items()) if dictionary else ([], [])
return cls(names, types)

def to_pandas(self):
"""Return the equivalent pandas datatypes."""
from ibis.backends.pandas.client import ibis_schema_to_pandas

return ibis_schema_to_pandas(self)

def to_pyarrow(self):
"""Return the equivalent pyarrow schema."""
from ibis.backends.pyarrow.datatypes import ibis_to_pyarrow_schema

return ibis_to_pyarrow_schema(self)

def __gt__(self, other: Schema) -> bool:
"""Return whether `self` is a strict superset of `other`."""
return set(self.items()) > set(other.items())
Expand Down

0 comments on commit 22f3b4d

Please sign in to comment.