Skip to content

Commit

Permalink
docs(examples): add temporal day_of_year example (#10376)
Browse files Browse the repository at this point in the history
<!--
Thanks for taking the time to contribute to Ibis!

Please ensure that your pull request title matches the conventional
commits
specification: https://www.conventionalcommits.org/en/v1.0.0/
-->

## Description of changes

This adds a temporal example for `day_of_year` to include a
demonstration of leap year behavior (365/366).
  • Loading branch information
IndexSeek authored Oct 26, 2024
1 parent 02efbb2 commit 40c14c3
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 40c14c3

Please sign in to comment.