From 40c14c3aae9fb9df36d8ee075e8242d046f5f70b Mon Sep 17 00:00:00 2001 From: Tyler White <50381805+IndexSeek@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:10:18 -0400 Subject: [PATCH] docs(examples): add temporal `day_of_year` example (#10376) ## Description of changes This adds a temporal example for `day_of_year` to include a demonstration of leap year behavior (365/366). --- ibis/expr/types/temporal.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/ibis/expr/types/temporal.py b/ibis/expr/types/temporal.py index dee526b1beb3..9a2c59b238a9 100644 --- a/ibis/expr/types/temporal.py +++ b/ibis/expr/types/temporal.py @@ -59,7 +59,37 @@ def day_of_week(self) -> DayOfWeek: return DayOfWeek(self) def day_of_year(self) -> ir.IntegerValue: - """Extract the day of the year component.""" + """Extract the day of the year component. + + Examples + -------- + >>> from datetime import date + >>> import ibis + >>> ibis.options.interactive = True + >>> t = ibis.memtable( + ... { + ... "date_col": [ + ... date(2023, 1, 1), + ... date(2023, 6, 17), + ... date(2023, 12, 31), + ... date(2024, 2, 29), + ... date(2024, 12, 31), + ... ] + ... }, + ... ) + >>> t.date_col.day_of_year() + ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + ┃ ExtractDayOfYear(date_col) ┃ + ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ + │ int32 │ + ├────────────────────────────┤ + │ 1 │ + │ 168 │ + │ 365 │ + │ 60 │ + │ 366 │ + └────────────────────────────┘ + """ return ops.ExtractDayOfYear(self).to_expr() def quarter(self) -> ir.IntegerValue: