Skip to content

Commit

Permalink
feat: return DSL string for DataDatatype.__repr__()
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews committed Jan 26, 2025
1 parent a410d3b commit 6ff129a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ibis/expr/datatypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def __str__(self) -> str:
prefix = "!" * (not self.nullable)
return f"{prefix}{self.name.lower()}{self._pretty_piece}"

def __repr__(self) -> str:
return str(self)

def equals(self, other):
if not isinstance(other, DataType):
raise TypeError(
Expand Down
10 changes: 5 additions & 5 deletions ibis/expr/datatypes/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,16 @@ def test_timestamp_with_invalid_timezone():
assert str(ts) == "timestamp('Foo/Bar&234')"


def test_timestamp_with_timezone_repr():
ts = dt.Timestamp("UTC")
assert repr(ts) == "Timestamp(timezone='UTC', scale=None, nullable=True)"


def test_timestamp_with_timezone_str():
ts = dt.Timestamp("UTC")
assert str(ts) == "timestamp('UTC')"


def test_timestamp_with_timezone_scale_str():
ts = dt.Timestamp("UTC", scale=4)
assert str(ts) == "timestamp('UTC', 4)"


def test_time_str():
assert str(dt.time) == "time"

Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/datatypes/tests/test_pandas_numpy_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,5 @@ def test_infer_numpy_array(numpy_array, expected_dtypes):
def test_normalize_non_convertible_boolean():
typ = dt.boolean
value = np.array([1, 2, 3])
with pytest.raises(TypeError, match="Unable to normalize .+ to Boolean"):
with pytest.raises(TypeError, match="Unable to normalize .+ to boolean"):
dt.normalize(typ, value)
4 changes: 2 additions & 2 deletions ibis/expr/datatypes/tests/test_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ def test_normalize_none_with_non_nullable_type():
@pytest.mark.parametrize("kind", ["uint", "int"])
def test_normalize_non_convertible_int(kind, bits):
typ = getattr(dt, f"{kind}{bits:d}")
with pytest.raises(TypeError, match="Unable to normalize .+ to U?Int"):
with pytest.raises(TypeError, match="Unable to normalize .+ to u?int"):
dt.normalize(typ, "not convertible")


@pytest.mark.parametrize("typename", ["float32", "float64"])
def test_normalize_non_convertible_float(typename):
typ = getattr(dt, typename)
with pytest.raises(TypeError, match="Unable to normalize .+ to Float"):
with pytest.raises(TypeError, match="Unable to normalize .+ to float"):
dt.normalize(typ, "not convertible")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Literal(1, Int8(nullable=True), 'foo') too many positional arguments
Literal(1, int8, 'foo') too many positional arguments

Expected signature: Literal(value: Annotated[Any, Not(pattern=InstanceOf(type=<class 'Deferred'>))], dtype: DataType)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Literal(1, Int8(nullable=True), name='foo') got an unexpected keyword argument 'name'
Literal(1, int8, name='foo') got an unexpected keyword argument 'name'

Expected signature: Literal(value: Annotated[Any, Not(pattern=InstanceOf(type=<class 'Deferred'>))], dtype: DataType)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Literal(1, Int8(nullable=True), dtype=Int16(nullable=True)) multiple values for argument 'dtype'
Literal(1, int8, dtype=int16) multiple values for argument 'dtype'

Expected signature: Literal(value: Annotated[Any, Not(pattern=InstanceOf(type=<class 'Deferred'>))], dtype: DataType)

0 comments on commit 6ff129a

Please sign in to comment.