Skip to content

Commit

Permalink
chore: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews committed Mar 19, 2024
1 parent 2ab8d9c commit 2fcf850
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
9 changes: 6 additions & 3 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@
def test_array_factory(con):
a = ibis.array([1, 2, 3])
assert con.execute(a) == [1, 2, 3]

a2 = ibis.array(a)
assert con.execute(a2) == [1, 2, 3]

typed = ibis.array([1, 2, 3], type="array<float64>")
assert con.execute(typed) == [1.0, 2.0, 3.0]

typed2 = ibis.array(a, type="array<float64>")
assert con.execute(typed2) == [1.0, 2.0, 3.0]

Expand All @@ -86,8 +89,8 @@ def test_array_factory_empty(con):
with pytest.raises(TypeError):
ibis.array([])

empty_typed = ibis.array([], type="array<float64>")
assert str(empty_typed.type()) == "array<float64>"
empty_typed = ibis.array([], type="array<float>")
assert empty_typed.type() == dt.Array(value_type=dt.float64)
assert con.execute(empty_typed) == []


Expand All @@ -100,7 +103,7 @@ def test_array_factory_null(con):
with pytest.raises(TypeError):
ibis.array(None)
none_typed = ibis.array(None, type="array<float64>")
assert str(none_typed.type()) == "array<float64>"
assert none_typed.type() == dt.Array(value_type=dt.float64)
assert con.execute(none_typed) is None


Expand Down
7 changes: 5 additions & 2 deletions ibis/backends/tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
def test_map_factory(con):
m = ibis.map({"a": 1, "b": 2})
assert con.execute(m) == {"a": 1, "b": 2}

m2 = ibis.map(m)
assert con.execute(m2) == {"a": 1, "b": 2}

typed = ibis.map({"a": 1, "b": 2}, type="map<string, float>")
assert con.execute(typed) == {"a": 1.0, "b": 2.0}

typed2 = ibis.map(m, type="map<string, float>")
assert con.execute(typed2) == {"a": 1.0, "b": 2.0}

Expand All @@ -57,7 +60,7 @@ def test_map_factory_empty(con):
with pytest.raises(TypeError):
ibis.map({})
empty_typed = ibis.map({}, type="map<string, string>")
assert str(empty_typed.type()) == "map<string, string>"
assert empty_typed.type() == dt.Map(key_type=dt.string, value_type=dt.string)
assert con.execute(empty_typed) == {}


Expand All @@ -68,7 +71,7 @@ def test_map_factory_null(con):
with pytest.raises(TypeError):
ibis.map(None)
null_typed = ibis.map(None, type="map<string, string>")
assert str(null_typed.type()) == "map<string, string>"
assert null_typed.type() == dt.Map(key_type=dt.string, value_type=dt.string)
assert con.execute(null_typed) is None


Expand Down
6 changes: 4 additions & 2 deletions ibis/backends/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@


@pytest.mark.notimpl(["postgres"])
# @pytest.mark.broken(["pandas", "dask"], reason="casting is broken")
def test_struct_factory(con):
s = ibis.struct({"a": 1, "b": 2})
assert con.execute(s) == {"a": 1, "b": 2}

s2 = ibis.struct(s)
assert con.execute(s2) == {"a": 1, "b": 2}

typed = ibis.struct({"a": 1, "b": 2}, type="struct<a: float64, b: float64>")
assert con.execute(typed) == {"a": 1.0, "b": 2.0}

typed2 = ibis.struct(s, type="struct<a: float64, b: float64>")
assert con.execute(typed2) == {"a": 1.0, "b": 2.0}

Expand All @@ -52,7 +54,7 @@ def test_struct_factory_null(con):
with pytest.raises(TypeError):
ibis.struct(None)
none_typed = ibis.struct(None, type="struct<a: float64, b: float>")
assert str(none_typed.type()) == "struct<a: float64, b: float64>"
assert none_typed.type() == dt.Struct(fields={"a": dt.float64, "b": dt.float64})
assert con.execute(none_typed) is None


Expand Down
3 changes: 2 additions & 1 deletion ibis/expr/types/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable

from ibis.expr.types import dt
import ibis.expr.datatypes as dt
from ibis.expr.types.typing import V

import ibis.common.exceptions as com
Expand Down Expand Up @@ -1082,6 +1082,7 @@ def __getitem__(self, index: int | ir.IntegerValue | slice) -> ir.Column:
@deferrable
def array(
values: ArrayValue | Iterable[V] | None,
*,
type: str | dt.DataType | None = None,
) -> ArrayValue:
"""Create an array expression.
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/types/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

from ibis.expr import datatypes as dt
import ibis.expr.datatypes as dt


@public
Expand Down
1 change: 1 addition & 0 deletions ibis/expr/types/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@deferrable
def struct(
value: Iterable[tuple[str, V]] | Mapping[str, V] | StructValue | None,
*,
type: str | dt.DataType | None = None,
) -> StructValue:
"""Create a struct expression.
Expand Down

0 comments on commit 2fcf850

Please sign in to comment.