diff --git a/CHANGELOG.md b/CHANGELOG.md index 93eda9e3a..224c342fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ ### Fixes +- Use `wday=0` for Mondays in `tick_calendar` (like `calendar_day_of_week`). + ## 0.1.5 ### Features diff --git a/temporian/core/operators/test/test_tick_calendar.py b/temporian/core/operators/test/test_tick_calendar.py index 59c43f6b7..00f847c51 100644 --- a/temporian/core/operators/test/test_tick_calendar.py +++ b/temporian/core/operators/test/test_tick_calendar.py @@ -145,7 +145,7 @@ def test_weekdays(self): timestamps=timestamps, ) - result = evset.tick_calendar(hour="*", wday=6) + result = evset.tick_calendar(hour="*", wday=5) assertOperatorResult(self, result, expected_evset, check_sampling=False) diff --git a/temporian/implementation/numpy/operators/tick_calendar.py b/temporian/implementation/numpy/operators/tick_calendar.py index 7e46500fd..b7ef5cddd 100644 --- a/temporian/implementation/numpy/operators/tick_calendar.py +++ b/temporian/implementation/numpy/operators/tick_calendar.py @@ -31,6 +31,14 @@ def __init__(self, operator: TickCalendar) -> None: assert isinstance(operator, TickCalendar) super().__init__(operator) + def _wday_py_to_cpp(self, py_wday: int) -> int: + """Converts wday number from Python (wday=0 for Monday) to C++ + convention (wday=0 for Sunday). + This is required to keep coherency between calendar_day_of_week() + operator (which uses datetime.weekday()) and tick_calendar() (which + uses tm_wday in tick_calendar.cc).""" + return (py_wday + 1) % 7 + def _get_arg_range( self, arg_value: Union[int, Literal["*"]], @@ -66,9 +74,12 @@ def __call__(self, input: EventSet) -> Dict[str, EventSet]: month_range = self._get_arg_range( self.operator.month, self.operator.month_max_range() ) - wday_range = self._get_arg_range( - self.operator.wday, self.operator.wday_max_range() - ) + + # Weekday: convert python (wday=0 for Mon) to C++ (wday=0 for Sun) + wday = self.operator.wday + if wday != "*": + wday = self._wday_py_to_cpp(wday) + wday_range = self._get_arg_range(wday, self.operator.wday_max_range()) # Fill output EventSet's data for index_key, index_data in input.data.items():