From 2b46aa6ad1a971ecd547622892a4130dbbd399cf Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 5 Feb 2025 05:56:59 -0500 Subject: [PATCH] refactor(api)!: change `as_interval` `unit` argument to be positional-only --- ibis/backends/tests/test_temporal.py | 4 ++-- ibis/expr/types/numeric.py | 4 +++- ibis/tests/expr/test_temporal.py | 26 +++++++++++++------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index 5f40d04f3165..901a75c176f3 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -556,7 +556,7 @@ def test_date_truncate(backend, alltypes, df, unit): def test_integer_to_interval_timestamp( backend, con, alltypes, df, unit, displacement_type ): - interval = alltypes.int_col.as_interval(unit=unit) + interval = alltypes.int_col.as_interval(unit) expr = (alltypes.timestamp_col + interval).name("tmp") def convert_to_offset(offset, displacement_type=displacement_type): @@ -629,7 +629,7 @@ def convert_to_offset(offset, displacement_type=displacement_type): @pytest.mark.notimpl(["datafusion", "druid"], raises=com.OperationNotDefinedError) @pytest.mark.notimpl(["exasol"], raises=com.OperationNotDefinedError) def test_integer_to_interval_date(backend, con, alltypes, df, unit): - interval = alltypes.int_col.as_interval(unit=unit) + interval = alltypes.int_col.as_interval(unit) month = alltypes.date_string_col[:2] day = alltypes.date_string_col[3:5] year = alltypes.date_string_col[6:8] diff --git a/ibis/expr/types/numeric.py b/ibis/expr/types/numeric.py index 3b46f5ed5b92..23a183f3dcbb 100644 --- a/ibis/expr/types/numeric.py +++ b/ibis/expr/types/numeric.py @@ -1454,6 +1454,7 @@ def as_timestamp(self, unit: Literal["s", "ms", "us"], /) -> ir.TimestampValue: def as_interval( self, unit: Literal["Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"] = "s", + /, ) -> ir.IntervalValue: """Convert an integer to an interval. @@ -1518,8 +1519,9 @@ def to_timestamp( def to_interval( self, unit: Literal["Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"] = "s", + /, ) -> ir.IntervalValue: - return self.as_interval(unit=unit) + return self.as_interval(unit) def convert_base( self, diff --git a/ibis/tests/expr/test_temporal.py b/ibis/tests/expr/test_temporal.py index eb590ace996c..9daf487abf5f 100644 --- a/ibis/tests/expr/test_temporal.py +++ b/ibis/tests/expr/test_temporal.py @@ -641,10 +641,10 @@ def test_integer_to_interval(column, unit, table): @pytest.mark.parametrize( "operands", [ - lambda t, u: (api.interval(3, unit=u), api.interval(2, unit=u)), - lambda t, u: (api.interval(3, unit=u), api.interval(3, unit=u)), - lambda t, u: (t.c.as_interval(unit=u), api.interval(2, unit=u)), - lambda t, u: (t.c.as_interval(unit=u), t.d.as_interval(unit=u)), + lambda _, u: (api.interval(3, unit=u), api.interval(2, unit=u)), + lambda _, u: (api.interval(3, unit=u), api.interval(3, unit=u)), + lambda t, u: (t.c.as_interval(u), api.interval(2, unit=u)), + lambda t, u: (t.c.as_interval(u), t.d.as_interval(u)), ], ) @pytest.mark.parametrize( @@ -688,15 +688,15 @@ def test_interval_comparisons(unit, operands, operator, table): @pytest.mark.parametrize( "interval", [ - lambda t: api.interval(years=4), - lambda t: api.interval(quarters=4), - lambda t: api.interval(months=3), - lambda t: api.interval(weeks=2), - lambda t: api.interval(days=1), - lambda t: t.c.as_interval(unit="Y"), - lambda t: t.c.as_interval(unit="M"), - lambda t: t.c.as_interval(unit="W"), - lambda t: t.c.as_interval(unit="D"), + lambda _: api.interval(years=4), + lambda _: api.interval(quarters=4), + lambda _: api.interval(months=3), + lambda _: api.interval(weeks=2), + lambda _: api.interval(days=1), + lambda t: t.c.as_interval("Y"), + lambda t: t.c.as_interval("M"), + lambda t: t.c.as_interval("W"), + lambda t: t.c.as_interval("D"), ], ids=[ "years",