@@ -267,6 +267,7 @@ def between(
267
267
self ,
268
268
lower : str | datetime .time | TimeValue ,
269
269
upper : str | datetime .time | TimeValue ,
270
+ * ,
270
271
timezone : str | None = None ,
271
272
) -> ir .BooleanValue :
272
273
"""Check if the expr falls between `lower` and `upper`, inclusive.
@@ -326,7 +327,7 @@ def between(
326
327
327
328
@public
328
329
class TimeValue (_TimeComponentMixin , Value ):
329
- def strftime (self , format_str : str ) -> ir .StringValue :
330
+ def strftime (self , format_str : str , / ) -> ir .StringValue :
330
331
"""Format a time according to `format_str`.
331
332
332
333
Format string may depend on the backend, but we try to conform to ANSI
@@ -344,7 +345,7 @@ def strftime(self, format_str: str) -> ir.StringValue:
344
345
"""
345
346
return ops .Strftime (self , format_str ).to_expr ()
346
347
347
- def truncate (self , unit : Literal ["h" , "m" , "s" , "ms" , "us" , "ns" ]) -> TimeValue :
348
+ def truncate (self , unit : Literal ["h" , "m" , "s" , "ms" , "us" , "ns" ], / ) -> TimeValue :
348
349
"""Truncate the expression to a time expression in units of `unit`.
349
350
350
351
Commonly used for time series resampling.
@@ -421,7 +422,9 @@ def __rsub__(self, other: ops.Value[dt.Interval | dt.Time, ds.Any]):
421
422
def delta (
422
423
self ,
423
424
other : datetime .time | Value [dt .Time ],
424
- part : Literal [
425
+ / ,
426
+ * ,
427
+ unit : Literal [
425
428
"hour" , "minute" , "second" , "millisecond" , "microsecond" , "nanosecond"
426
429
]
427
430
| Value [dt .String ],
@@ -438,7 +441,7 @@ def delta(
438
441
----------
439
442
other
440
443
A time expression
441
- part
444
+ unit
442
445
The unit of time to compute the difference in
443
446
444
447
Returns
@@ -452,7 +455,7 @@ def delta(
452
455
>>> ibis.options.interactive = True
453
456
>>> start = ibis.time("01:58:00")
454
457
>>> end = ibis.time("23:59:59")
455
- >>> end.delta(start, "hour")
458
+ >>> end.delta(start, unit= "hour")
456
459
┌────┐
457
460
│ 22 │
458
461
└────┘
@@ -467,7 +470,7 @@ def delta(
467
470
>>> taxi = ibis.read_csv("/tmp/triptimes.csv")
468
471
>>> ride_duration = (
469
472
... taxi.tpep_dropoff_datetime.time()
470
- ... .delta(taxi.tpep_pickup_datetime.time(), "minute")
473
+ ... .delta(taxi.tpep_pickup_datetime.time(), unit= "minute")
471
474
... .name("ride_minutes")
472
475
... )
473
476
>>> ride_duration
@@ -483,7 +486,7 @@ def delta(
483
486
│ 5 │
484
487
└──────────────┘
485
488
"""
486
- return ops .TimeDelta (left = self , right = other , part = part ).to_expr ()
489
+ return ops .TimeDelta (left = self , right = other , part = unit ).to_expr ()
487
490
488
491
489
492
@public
@@ -498,7 +501,7 @@ class TimeColumn(Column, TimeValue):
498
501
499
502
@public
500
503
class DateValue (Value , _DateComponentMixin ):
501
- def strftime (self , format_str : str ) -> ir .StringValue :
504
+ def strftime (self , format_str : str , / ) -> ir .StringValue :
502
505
"""Format a date according to `format_str`.
503
506
504
507
Format string may depend on the backend, but we try to conform to ANSI
@@ -557,7 +560,7 @@ def strftime(self, format_str: str) -> ir.StringValue:
557
560
"""
558
561
return ops .Strftime (self , format_str ).to_expr ()
559
562
560
- def truncate (self , unit : Literal ["Y" , "Q" , "M" , "W" , "D" ]) -> DateValue :
563
+ def truncate (self , unit : Literal ["Y" , "Q" , "M" , "W" , "D" ], / ) -> DateValue :
561
564
"""Truncate date expression to units of `unit`.
562
565
563
566
Parameters
@@ -668,7 +671,9 @@ def __rsub__(self, other: ops.Value[dt.Date | dt.Interval, ds.Any]):
668
671
def delta (
669
672
self ,
670
673
other : datetime .date | Value [dt .Date ],
671
- part : Literal ["year" , "quarter" , "month" , "week" , "day" ] | Value [dt .String ],
674
+ / ,
675
+ * ,
676
+ unit : Literal ["year" , "quarter" , "month" , "week" , "day" ] | Value [dt .String ],
672
677
) -> ir .IntegerValue :
673
678
"""Compute the number of `part`s between two dates.
674
679
@@ -682,7 +687,7 @@ def delta(
682
687
----------
683
688
other
684
689
A date expression
685
- part
690
+ unit
686
691
The unit of time to compute the difference in
687
692
688
693
Returns
@@ -696,14 +701,14 @@ def delta(
696
701
>>> ibis.options.interactive = True
697
702
>>> start = ibis.date("1992-09-30")
698
703
>>> end = ibis.date("1992-10-01")
699
- >>> end.delta(start, "day")
704
+ >>> end.delta(start, unit= "day")
700
705
┌───┐
701
706
│ 1 │
702
707
└───┘
703
708
>>> prez = ibis.examples.presidential.fetch()
704
709
>>> prez.mutate(
705
- ... years_in_office=prez.end.delta(prez.start, "year"),
706
- ... hours_in_office=prez.end.delta(prez.start, "hour"),
710
+ ... years_in_office=prez.end.delta(prez.start, unit= "year"),
711
+ ... hours_in_office=prez.end.delta(prez.start, unit= "hour"),
707
712
... ).drop("party")
708
713
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
709
714
┃ name ┃ start ┃ end ┃ years_in_office ┃ hours_in_office ┃
@@ -723,7 +728,7 @@ def delta(
723
728
│ … │ … │ … │ … │ … │
724
729
└────────────┴────────────┴────────────┴─────────────────┴─────────────────┘
725
730
"""
726
- return ops .DateDelta (left = self , right = other , part = part ).to_expr ()
731
+ return ops .DateDelta (left = self , right = other , part = unit ).to_expr ()
727
732
728
733
def epoch_days (self ) -> ir .IntegerValue :
729
734
"""Return the number of days since the UNIX epoch date.
@@ -759,7 +764,7 @@ def epoch_days(self) -> ir.IntegerValue:
759
764
│ 2020-01-01 │ 18262 │
760
765
└────────────┴───────┘
761
766
"""
762
- return self .delta (ibis .date (1970 , 1 , 1 ), "day" )
767
+ return self .delta (ibis .date (1970 , 1 , 1 ), unit = "day" )
763
768
764
769
765
770
@public
@@ -774,7 +779,7 @@ class DateColumn(Column, DateValue):
774
779
775
780
@public
776
781
class TimestampValue (_DateComponentMixin , _TimeComponentMixin , Value ):
777
- def strftime (self , format_str : str ) -> ir .StringValue :
782
+ def strftime (self , format_str : str , / ) -> ir .StringValue :
778
783
"""Format a timestamp according to `format_str`.
779
784
780
785
Format string may depend on the backend, but we try to conform to ANSI
@@ -847,8 +852,7 @@ def strftime(self, format_str: str) -> ir.StringValue:
847
852
return ops .Strftime (self , format_str ).to_expr ()
848
853
849
854
def truncate (
850
- self ,
851
- unit : Literal ["Y" , "Q" , "M" , "W" , "D" , "h" , "m" , "s" , "ms" , "us" , "ns" ],
855
+ self , unit : Literal ["Y" , "Q" , "M" , "W" , "D" , "h" , "m" , "s" , "ms" , "us" , "ns" ], /
852
856
) -> TimestampValue :
853
857
"""Truncate timestamp expression to units of `unit`.
854
858
@@ -935,6 +939,7 @@ def truncate(
935
939
def bucket (
936
940
self ,
937
941
interval : Any = None ,
942
+ / ,
938
943
* ,
939
944
years : int | None = None ,
940
945
quarters : int | None = None ,
@@ -1146,7 +1151,9 @@ def __rsub__(self, other: ops.Value[dt.Timestamp | dt.Interval, ds.Any]):
1146
1151
def delta (
1147
1152
self ,
1148
1153
other : datetime .datetime | Value [dt .Timestamp ],
1149
- part : Literal [
1154
+ / ,
1155
+ * ,
1156
+ unit : Literal [
1150
1157
"year" ,
1151
1158
"quarter" ,
1152
1159
"month" ,
@@ -1173,7 +1180,7 @@ def delta(
1173
1180
----------
1174
1181
other
1175
1182
A timestamp expression
1176
- part
1183
+ unit
1177
1184
The unit of time to compute the difference in
1178
1185
1179
1186
Returns
@@ -1187,7 +1194,7 @@ def delta(
1187
1194
>>> ibis.options.interactive = True
1188
1195
>>> start = ibis.time("01:58:00")
1189
1196
>>> end = ibis.time("23:59:59")
1190
- >>> end.delta(start, "hour")
1197
+ >>> end.delta(start, unit= "hour")
1191
1198
┌────┐
1192
1199
│ 22 │
1193
1200
└────┘
@@ -1201,7 +1208,7 @@ def delta(
1201
1208
... nbytes = f.write(data) # nbytes is unused
1202
1209
>>> taxi = ibis.read_csv("/tmp/triptimes.csv")
1203
1210
>>> ride_duration = taxi.tpep_dropoff_datetime.delta(
1204
- ... taxi.tpep_pickup_datetime, "minute"
1211
+ ... taxi.tpep_pickup_datetime, unit= "minute"
1205
1212
... ).name("ride_minutes")
1206
1213
>>> ride_duration
1207
1214
┏━━━━━━━━━━━━━━┓
@@ -1216,7 +1223,7 @@ def delta(
1216
1223
│ 5 │
1217
1224
└──────────────┘
1218
1225
"""
1219
- return ops .TimestampDelta (left = self , right = other , part = part ).to_expr ()
1226
+ return ops .TimestampDelta (left = self , right = other , part = unit ).to_expr ()
1220
1227
1221
1228
1222
1229
@public
@@ -1231,7 +1238,7 @@ class TimestampColumn(Column, TimestampValue):
1231
1238
1232
1239
@public
1233
1240
class IntervalValue (Value ):
1234
- def as_unit (self , target_unit : str ) -> IntervalValue :
1241
+ def as_unit (self , target_unit : str , / ) -> IntervalValue :
1235
1242
"""Convert this interval to units of `target_unit`."""
1236
1243
# TODO(kszucs): should use a separate operation for unit conversion
1237
1244
# which we can rewrite/simplify to integer multiplication/division
@@ -1251,8 +1258,8 @@ def as_unit(self, target_unit: str) -> IntervalValue:
1251
1258
return value .as_interval (target_unit )
1252
1259
1253
1260
@deprecated (as_of = "10.0" , instead = "use as_unit() instead" )
1254
- def to_unit (self , target_unit : str ) -> IntervalValue :
1255
- return self .as_unit (target_unit = target_unit )
1261
+ def to_unit (self , target_unit : str , / ) -> IntervalValue :
1262
+ return self .as_unit (target_unit )
1256
1263
1257
1264
@property
1258
1265
def years (self ) -> ir .IntegerValue :
0 commit comments