Skip to content

Commit f88521e

Browse files
committed
chore: apply review suggestions
1 parent 1650d7d commit f88521e

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
@@ -755,16 +755,16 @@ def from_unit(cls, unit, timezone=None, nullable=True) -> Self:
755755
return cls(scale=scale, timezone=timezone, nullable=nullable)
756756

757757
@classmethod
758-
def from_datetime(
759-
cls, dt: pydatetime.datetime, timezone: str | None = None, nullable: bool = True
760-
):
758+
def from_datetime(cls, dt: pydatetime.datetime, *, nullable: bool = True):
761759
"""Infer from a python datetime.datetime object."""
762760
if dt.microsecond:
763761
scale = 6
764762
else:
765763
scale = 0
766-
if timezone is None and dt.tzinfo is not None:
764+
if dt.tzinfo is not None:
767765
timezone = str(dt.tzinfo)
766+
else:
767+
timezone = None
768768
return cls(scale=scale, timezone=timezone, nullable=nullable)
769769

770770
@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)