Skip to content

Commit

Permalink
fix(dtypes): switch scale and timestamp parameter order when formatti…
Browse files Browse the repository at this point in the history
…ng a timestamp datatype
  • Loading branch information
kszucs authored and cpcloud committed Sep 3, 2023
1 parent 8d81e62 commit 302b122
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions ibis/expr/datatypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,14 @@ def unit(self) -> str:

@property
def _pretty_piece(self) -> str:
pieces = [
repr(piece) for piece in (self.scale, self.timezone) if piece is not None
]
return f"({', '.join(pieces)})" * bool(pieces)
if self.scale is not None and self.timezone is not None:
return f"('{self.timezone}', {self.scale:d})"
elif self.timezone is not None:
return f"('{self.timezone}')"
elif self.scale is not None:
return f"({self.scale:d})"
else:
return ""


@public
Expand Down
7 changes: 4 additions & 3 deletions ibis/expr/datatypes/tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ def test_parse_timestamp_with_timezone_invalid_timezone():
@pytest.mark.parametrize("scale", range(10))
@pytest.mark.parametrize("tz", ["UTC", "America/New_York"])
def test_parse_timestamp_with_scale(scale, tz):
assert dt.parse(f"timestamp({tz!r}, {scale:d})") == dt.Timestamp(
timezone=tz, scale=scale
)
expected = dt.Timestamp(timezone=tz, scale=scale)
typestring = f"timestamp({tz!r}, {scale:d})"
assert dt.parse(typestring) == expected
assert str(expected) == typestring


@pytest.mark.parametrize("scale", range(10))
Expand Down

0 comments on commit 302b122

Please sign in to comment.