ibis
ibis copied to clipboard
feat(api): `day_of_week.iso_index()` method
Description of changes
Added a new isoday_of_week method for timestamps.
Issues closed
Resolves #8989
ACTION NEEDED
Ibis follows the Conventional Commits specification for release automation.
The PR title and description are used as the merge commit message.
Please update your PR title and description to match the specification.
We have a DayOfWeek class defined in ibis/expr/types/temporal.py.
It's a bit of an oddball API in that it functions like a namespace instead of top level method like everything else.
Naturally, your first development experience with Ibis is extending a slightly weird bit of the codebase ๐.
Perhaps we can add two new methods there?
class DayOfWeek:
...
def iso_index(self): ...
def iso_full_name(self): ...
for consistency with the surrounding methods?
Here's a usage example:
In [8]: t = ibis.read_parquet("/data/avg_duration_over_time.parquet")
In [9]: t.head()
Out[9]:
โโโโโโโโโโโโโโณโโโโโโโโโโโโโโโโโ
โ date โ avg_duration_m โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ date โ float64 โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโค
โ 2024-04-16 โ 57.833333 โ
โ 2024-04-15 โ 42.833333 โ
โ 2024-04-14 โ 31.500000 โ
โ 2024-04-13 โ 53.600000 โ
โ 2024-04-12 โ 47.400000 โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
In [10]: t.select(
...: "date",
...: weekday=t.date.day_of_week.index(),
...: weekday_name=t.date.day_of_week.full_name(),
...: )
Out[10]:
โโโโโโโโโโโโโโณโโโโโโโโโโณโโโโโโโโโโโโโโโ
โ date โ weekday โ weekday_name โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ date โ int16 โ string โ
โโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโค
โ 2024-04-16 โ 1 โ Tuesday โ
โ 2024-04-15 โ 0 โ Monday โ
โ 2024-04-14 โ 6 โ Sunday โ
โ 2024-04-13 โ 5 โ Saturday โ
โ 2024-04-12 โ 4 โ Friday โ
โ 2024-04-10 โ 2 โ Wednesday โ
โ 2024-04-09 โ 1 โ Tuesday โ
โ 2024-04-07 โ 6 โ Sunday โ
โ 2024-04-06 โ 5 โ Saturday โ
โ 2024-04-05 โ 4 โ Friday โ
โ โฆ โ โฆ โ โฆ โ
โโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโ
Alternatively, I can take a crack at this one, if you want to handle iso_year()
We have a
DayOfWeekclass defined inibis/expr/types/temporal.py.
I missed that.
Alternatively, I can take a crack at this one, if you want to handle iso_year()
I'll give it a try. And iso_yearwith a different PR.
Is it possible that there are currently no tests for .day_of_week.index and .day_of_week.full_name? Was looking to place a test nearby but couldn't find them.
@kaijennissen You should be able to find the tests that run across backends in ibis/backends/tests/test_temporal.py:
โฏ rg test_day_of_week
ibis/backends/bigquery/tests/unit/test_compiler.py
72:def test_day_of_week(case, dtype, snapshot):
ibis/backends/impala/tests/test_client.py
202:def test_day_of_week(con):
ibis/backends/tests/test_temporal.py
1463:def test_day_of_week_scalar(con, date, expected_index, expected_day):
1484:def test_day_of_week_column(backend, alltypes, df):
1529:def test_day_of_week_column_group_by(
@cpcloud The sqlite tests pass locally. The exasol as well as the impala containers do not work thus I cannot test this locally. I have to investigate this a little deeper. I have no idea why the docs-test fails.
@kaijennissen Are you still interested in this feature? If so, would you mind trying it out for your use case and reporting back?
@cpcloud Sorry for the late answer. It works for my use case, thanks.