pitrou commented on code in PR #12657:
URL: https://github.com/apache/arrow/pull/12657#discussion_r855186269
##########
python/pyarrow/_compute.pyx:
##########
@@ -901,10 +903,20 @@ class RoundTemporalOptions(_RoundTemporalOptions):
"nanosecond".
week_starts_monday : bool, default True
If True, weeks start on Monday; if False, on Sunday.
+ strict_ceil : bool, default False
+ If True times exactly on unit multiple boundary will be rounded
+ one unit multiple up. This applies for ceiling only.
+ calendar_based_origin : bool, default False
+ By default origin is 1970-01-01T00:00:00. By setting this to True,
+ rounding origin will be beginning of one less precise calendar unit.
+ E.g.: rounding to hours will use beginning of day as origin.
+
"""
- def __init__(self, multiple=1, unit="day", week_starts_monday=True):
- self._set_options(multiple, unit, week_starts_monday)
+ def __init__(self, multiple=1, unit="day", *, week_starts_monday=True,
Review Comment:
Cool!
##########
cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc:
##########
@@ -728,18 +798,31 @@ const Duration FloorTimePoint(const int64_t arg, const
int64_t multiple,
}
template <typename Duration, typename Localizer>
-const Duration FloorWeekTimePoint(const int64_t arg, const int64_t multiple,
+const Duration FloorWeekTimePoint(const int64_t arg, const
RoundTemporalOptions options,
Localizer localizer_, const Duration
weekday_offset,
Status* st) {
const auto t = localizer_.template ConvertTimePoint<Duration>(arg) +
weekday_offset;
const weeks d = floor<weeks>(t).time_since_epoch();
- if (multiple == 1) {
+ if (options.multiple == 1) {
return localizer_.template
ConvertLocalToSys<Duration>(duration_cast<Duration>(d),
st) -
weekday_offset;
+ } else if (options.calendar_based_origin) {
+ weekday wd_;
Review Comment:
Hmm, did you forget to push an update?
##########
cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc:
##########
@@ -689,11 +689,27 @@ struct IsDaylightSavings {
// Round temporal values to given frequency
template <typename Duration, typename Localizer>
-year_month_day GetFlooredYmd(int64_t arg, int multiple, Localizer localizer_) {
+year_month_day GetFlooredYmd(int64_t arg, const int multiple,
+ const RoundTemporalOptions options, Localizer
localizer_) {
year_month_day ymd{floor<days>(localizer_.template
ConvertTimePoint<Duration>(arg))};
if (multiple == 1) {
return year_month_day(ymd.year() / ymd.month() / 1);
+ } else if (options.calendar_based_origin) {
+ switch (options.unit) {
+ case compute::CalendarUnit::MONTH: {
+ const auto m =
+ static_cast<uint32_t>(ymd.month()) / options.multiple *
options.multiple;
+ return year_month_day(ymd.year() / 1 / 1) + months{m};
+ }
+ case compute::CalendarUnit::QUARTER: {
+ const auto m = static_cast<uint32_t>(ymd.month()) / (options.multiple
* 3) *
+ (options.multiple * 3);
+ return year_month_day(ymd.year() / 1 / 1) + months{m};
+ }
+ default:
+ return ymd;
Review Comment:
Ok, just add a comment about it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]