Skip to content

Commit

Permalink
refactor(api)!: change as_timestamp unit argument to be positiona…
Browse files Browse the repository at this point in the history
…l-only
  • Loading branch information
cpcloud committed Feb 6, 2025
1 parent c5800c2 commit 178dd77
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/tests/unit/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_hashbytes(case, how, dtype, snapshot):
),
)
def test_integer_to_timestamp(case, unit, snapshot):
expr = ibis.literal(case, type=dt.int64).as_timestamp(unit=unit).name("tmp")
expr = ibis.literal(case, type=dt.int64).as_timestamp(unit).name("tmp")
snapshot.assert_match(to_sql(expr), "out.sql")


Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/druid/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def functional_alltypes(self) -> ir.Table:
# tool that calls itself a time series database or "good for
# working with time series", that lacks a first-class timestamp
# type.
timestamp_col=t.timestamp_col.as_timestamp(unit="ms"),
timestamp_col=t.timestamp_col.as_timestamp("ms"),
)

@property
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/flink/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_count_star(simple_table, assert_sql):
],
)
def test_timestamp_from_unix(simple_table, unit, assert_sql):
expr = simple_table.d.as_timestamp(unit=unit)
expr = simple_table.d.as_timestamp(unit)
assert_sql(expr)


Expand Down
20 changes: 7 additions & 13 deletions ibis/expr/types/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,10 +1420,7 @@ def approx_quantile(

@public
class IntegerValue(NumericValue):
def as_timestamp(
self,
unit: Literal["s", "ms", "us"],
) -> ir.TimestampValue:
def as_timestamp(self, unit: Literal["s", "ms", "us"], /) -> ir.TimestampValue:
"""Convert an integral UNIX timestamp to a timestamp expression.
Parameters
Expand All @@ -1440,11 +1437,7 @@ def as_timestamp(
--------
>>> import ibis
>>> ibis.options.interactive = True
>>> t = ibis.memtable(
... {
... "int_col": [0, 1730501716, 2147483647],
... }
... )
>>> t = ibis.memtable({"int_col": [0, 1730501716, 2147483647]})
>>> t.int_col.as_timestamp("s")
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ TimestampFromUNIX(int_col, SECOND) ┃
Expand Down Expand Up @@ -1513,12 +1506,13 @@ def as_interval(
"""
return ops.IntervalFromInteger(self, unit).to_expr()

@deprecated(as_of="10.0", removed_in="11.0", instead="use as_timestamp() instead")
@deprecated(
as_of="10.0", removed_in="11.0", instead="use as_timestamp(unit) instead"
)
def to_timestamp(
self,
unit: Literal["s", "ms", "us"] = "s",
self, unit: Literal["s", "ms", "us"] = "s", /
) -> ir.TimestampValue:
return self.as_timestamp(unit=unit)
return self.as_timestamp(unit)

@deprecated(as_of="10.0", removed_in="11.0", instead="use as_interval() instead")
def to_interval(
Expand Down

0 comments on commit 178dd77

Please sign in to comment.