Skip to content

Commit c0b98de

Browse files
committed
chore: apply review suggestions
1 parent 7a0bb77 commit c0b98de

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

ibis/expr/api.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,8 @@ def timestamp(
893893
is_ymdhms = any(a is not None for a in args[1:])
894894

895895
if is_ymdhms:
896-
if timezone is not None:
897-
raise NotImplementedError(
898-
"Timezone currently not supported when creating a timestamp from components"
899-
)
900-
return ops.TimestampFromYMDHMS(*args, nullable=nullable).to_expr()
896+
dtype = dt.Timestamp(timezone=timezone, nullable=nullable, scale=0)
897+
return ops.TimestampFromYMDHMS(*args, dtype=dtype).to_expr()
901898
elif isinstance(value_or_year, (numbers.Real, ir.IntegerValue)):
902899
raise TypeError("Use ibis.literal(...).as_timestamp() instead")
903900
elif isinstance(value_or_year, ir.Expr):
@@ -906,7 +903,7 @@ def timestamp(
906903
value = normalize_datetime(value_or_year)
907904
tzinfo = normalize_timezone(timezone or value.tzinfo)
908905
timezone = tzinfo.tzname(value) if tzinfo is not None else None
909-
dtype = dt.Timestamp.from_datetime(value, timezone=timezone, nullable=nullable)
906+
dtype = dt.Timestamp.from_datetime(value, nullable=nullable)
910907
return literal(value, type=dtype)
911908

912909

ibis/expr/datatypes/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,16 +647,16 @@ def from_unit(cls, unit, timezone=None, nullable=True):
647647
return cls(scale=scale, timezone=timezone, nullable=nullable)
648648

649649
@classmethod
650-
def from_datetime(
651-
cls, dt: pydatetime.datetime, timezone: str | None = None, nullable: bool = True
652-
):
650+
def from_datetime(cls, dt: pydatetime.datetime, *, nullable: bool = True):
653651
"""Infer from a python datetime.datetime object."""
654652
if dt.microsecond:
655653
scale = 6
656654
else:
657655
scale = 0
658-
if timezone is None and dt.tzinfo is not None:
656+
if dt.tzinfo is not None:
659657
timezone = str(dt.tzinfo)
658+
else:
659+
timezone = None
660660
return cls(scale=scale, timezone=timezone, nullable=nullable)
661661

662662
@classmethod

ibis/expr/operations/temporal.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,10 @@ class TimestampFromYMDHMS(Value):
258258
hours: Value[dt.Integer]
259259
minutes: Value[dt.Integer]
260260
seconds: Value[dt.Integer]
261-
nullable: bool = True
262261

262+
dtype: dt.Timestamp
263263
shape = rlz.shape_like(["year", "month", "day", "hours", "minutes", "seconds"])
264264

265-
@attribute
266-
def dtype(self):
267-
return dt.Timestamp(
268-
nullable=self.nullable,
269-
timezone=None,
270-
scale=0, # second precision
271-
)
272-
273265

274266
@public
275267
class TimestampFromUNIX(Value):

0 commit comments

Comments
 (0)