Skip to content

Commit

Permalink
chore: split up examples and shorten column names
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Oct 26, 2024
1 parent e3d6462 commit 3aa6317
Showing 1 changed file with 57 additions and 46 deletions.
103 changes: 57 additions & 46 deletions ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,21 @@ def truncate(self, unit: Literal["Y", "Q", "M", "W", "D"]) -> DateValue:
week.
>>> t.select(
... truncated_year=t.date_col.truncate("Y"),
... truncated_quarter=t.date_col.truncate("Q"),
... truncated_month=t.date_col.truncate("M"),
... truncated_week=t.date_col.truncate("W"),
... year=t.date_col.truncate("Y"),
... quarter=t.date_col.truncate("Q"),
... month=t.date_col.truncate("M"),
... week=t.date_col.truncate("W"),
... )
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
truncated_year ┃ truncated_quarter ┃ truncated_month ┃ truncated_week
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ date │ date │ date │ date
├────────────────┼───────────────────┼─────────────────┼────────────────┤
│ 2020-01-01 │ 2020-01-01 │ 2020-01-01 │ 2019-12-30
│ 2020-01-01 │ 2020-04-01 │ 2020-04-01 │ 2020-04-06
│ 2020-01-01 │ 2020-07-01 │ 2020-07-01 │ 2020-07-13
│ 2020-01-01 │ 2020-10-01 │ 2020-10-01 │ 2020-10-19
└────────────────┴───────────────────┴─────────────────┴────────────────┘
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
year ┃ quarter ┃ month ┃ week
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ date │ date │ date │ date │
├────────────┼────────────┼────────────────────────┤
│ 2020-01-01 │ 2020-01-01 │ 2020-01-01 │ 2019-12-30 │
│ 2020-01-01 │ 2020-04-01 │ 2020-04-01 │ 2020-04-06 │
│ 2020-01-01 │ 2020-07-01 │ 2020-07-01 │ 2020-07-13 │
│ 2020-01-01 │ 2020-10-01 │ 2020-10-01 │ 2020-10-19 │
└────────────┴────────────┴────────────────────────┘
"""
return ops.DateTruncate(self, unit).to_expr()

Expand Down Expand Up @@ -704,45 +704,56 @@ def truncate(
... },
... )
Return timestamp columns truncated to the start of the year, quarter, month,
and week.
Return timestamp columns truncated to the start of the year, quarter, and month.
>>> t.select(
... truncated_year=t.timestamp_col.truncate("Y"),
... truncated_quarter=t.timestamp_col.truncate("Q"),
... truncated_month=t.timestamp_col.truncate("M"),
... truncated_week=t.timestamp_col.truncate("W"),
... year=t.timestamp_col.truncate("Y"),
... quarter=t.timestamp_col.truncate("Q"),
... month=t.timestamp_col.truncate("M"),
... )
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ truncated_year ┃ truncated_quarter ┃ truncated_month ┃ truncated_week ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ timestamp │ timestamp │ timestamp │ timestamp │
├─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────┤
│ 2020-01-01 00:00:00 │ 2020-01-01 00:00:00 │ 2020-01-01 00:00:00 │ 2019-12-30 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-04-01 00:00:00 │ 2020-04-01 00:00:00 │ 2020-04-06 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-07-01 00:00:00 │ 2020-07-01 00:00:00 │ 2020-07-13 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-10-01 00:00:00 │ 2020-10-01 00:00:00 │ 2020-10-19 00:00:00 │
└─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────┘
Return timestamp columns truncated to the start of the day, hour, minute, and
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ year ┃ quarter ┃ month ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ timestamp │ timestamp │ timestamp │
├─────────────────────┼─────────────────────┼─────────────────────┤
│ 2020-01-01 00:00:00 │ 2020-01-01 00:00:00 │ 2020-01-01 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-04-01 00:00:00 │ 2020-04-01 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-07-01 00:00:00 │ 2020-07-01 00:00:00 │
│ 2020-01-01 00:00:00 │ 2020-10-01 00:00:00 │ 2020-10-01 00:00:00 │
└─────────────────────┴─────────────────────┴─────────────────────┘
Return timestamp columns truncated to the start of the week and day.
>>> t.select(week=t.timestamp_col.truncate("W"), day=t.timestamp_col.truncate("D"))
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ week ┃ day ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ timestamp │ timestamp │
├─────────────────────┼─────────────────────┤
│ 2019-12-30 00:00:00 │ 2020-01-05 00:00:00 │
│ 2020-04-06 00:00:00 │ 2020-04-10 00:00:00 │
│ 2020-07-13 00:00:00 │ 2020-07-15 00:00:00 │
│ 2020-10-19 00:00:00 │ 2020-10-20 00:00:00 │
└─────────────────────┴─────────────────────┘
Return timestamp columns truncated to the start of the hour, minute, and
second.
>>> t.select(
... truncated_day=t.timestamp_col.truncate("D"),
... truncated_hour=t.timestamp_col.truncate("h"),
... truncated_minute=t.timestamp_col.truncate("m"),
... truncated_second=t.timestamp_col.truncate("s"),
... hour=t.timestamp_col.truncate("h"),
... minute=t.timestamp_col.truncate("m"),
... second=t.timestamp_col.truncate("s"),
... )
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━
truncated_day ┃ truncated_hour ┃ truncated_minute ┃ truncated_second
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━
│ timestamp │ timestamp │ timestamp │ timestamp │
├─────────────────────┼─────────────────────┼─────────────────────┼─────────────────────
│ 2020-01-05 00:00:00 │ 2020-01-05 08:00:00 │ 2020-01-05 08:00:00 │ 2020-01-05 08:00:00 │
│ 2020-04-10 00:00:00 │ 2020-04-10 10:00:00 │ 2020-04-10 10:02:00 │ 2020-04-10 10:02:15 │
│ 2020-07-15 00:00:00 │ 2020-07-15 12:00:00 │ 2020-07-15 12:04:00 │ 2020-07-15 12:04:30 │
│ 2020-10-20 00:00:00 │ 2020-10-20 14:00:00 │ 2020-10-20 14:06:00 │ 2020-10-20 14:06:45 │
└─────────────────────┴─────────────────────┴─────────────────────┴─────────────────────
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
hour ┃ minute ┃ second
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ timestamp │ timestamp │ timestamp │
├─────────────────────┼─────────────────────┼─────────────────────┤
│ 2020-01-05 08:00:00 │ 2020-01-05 08:00:00 │ 2020-01-05 08:00:00 │
│ 2020-04-10 10:00:00 │ 2020-04-10 10:02:00 │ 2020-04-10 10:02:15 │
│ 2020-07-15 12:00:00 │ 2020-07-15 12:04:00 │ 2020-07-15 12:04:30 │
│ 2020-10-20 14:00:00 │ 2020-10-20 14:06:00 │ 2020-10-20 14:06:45 │
└─────────────────────┴─────────────────────┴─────────────────────┘
"""
return ops.TimestampTruncate(self, unit).to_expr()

Expand Down

0 comments on commit 3aa6317

Please sign in to comment.