Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datatypes): fix bad references in to_numpy() #7910

Merged
merged 2 commits into from
Jan 4, 2024
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
4 changes: 2 additions & 2 deletions ibis/expr/datatypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ def from_dask(cls, dask_type, nullable=True) -> Self:

def to_numpy(self):
"""Return the equivalent numpy datatype."""
from ibis.formats.numpy import NumpyFormat
from ibis.formats.numpy import NumpyType

return NumpyFormat.from_dtype(self)
return NumpyType.from_ibis(self)

def to_pandas(self):
"""Return the equivalent pandas datatype."""
Expand Down
21 changes: 21 additions & 0 deletions ibis/expr/datatypes/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Annotated, NamedTuple

import pytest
from pytest import param

import ibis.expr.datatypes as dt
from ibis.common.annotations import ValidationError
Expand Down Expand Up @@ -672,3 +673,23 @@ def test_type_coercion():
p = Pattern.from_typehint(Annotated[dt.Interval, Attrs(unit=As(TimeUnit))])
assert p.match(dt.Interval("s"), {}) == dt.Interval("s")
assert p.match(dt.Interval("ns"), {}) == dt.Interval("ns")


@pytest.mark.parametrize(
"dtype",
[
param(dt.int16, id="int16"),
param(dt.int32, id="int32"),
param(dt.int64, id="int64"),
param(dt.uint8, id="uint8"),
param(dt.uint16, id="uint16"),
param(dt.uint32, id="uint32"),
param(dt.uint64, id="uint64"),
param(dt.float32, id="float32"),
param(dt.float64, id="float64"),
param(dt.boolean, id="boolean"),
],
)
@pytest.mark.parametrize("fmt", ["numpy", "pandas", "pyarrow"])
def test_type_roundtrip(dtype, fmt):
assert getattr(dt.DataType, f"from_{fmt}")(getattr(dtype, f"to_{fmt}")()) == dtype