hamilton-earthscope opened a new pull request, #572:
URL: https://github.com/apache/arrow-go/pull/572

   ### Rationale for this change
   
   Apache Arrow Go lacks temporal rounding functionality available in PyArrow 
(`floor_temporal`, `ceil_temporal`, `round_temporal`) - 
[reference](https://arrow.apache.org/docs/python/generated/pyarrow.compute.floor_temporal.html).
 This prevents users from rounding timestamp or date values to calendar units 
(year, quarter, month, week, day) and sub-day units (hour, minute, second, 
etc.), which is essential for time-series data aggregation and analysis.
   
   ### What changes are included in this PR?
   
   - **New compute functions**: `FloorTemporal`, `CeilTemporal`, 
`RoundTemporal` with support for:
     - Calendar units: year, quarter, month, week, day
     - Sub-day units: hour, minute, second, millisecond, microsecond, nanosecond
     - Multiple rounding: round to N units (e.g., 2-week, 3-month periods)
     - Rounding modes: floor, ceil, half-up, half-down, half-to-even
     - Timezone-aware rounding: respects DST and local date boundaries
     - Calendar-based origin: round relative to start of day for sub-day units
   
   - **Implementation details**:
     - `RoundTemporalOptions` for configuring unit, multiple, week start, 
strict ceiling, and calendar origin
     - Timezone-aware calendar arithmetic for variable-length periods
     - Support for timezone-naive and timezone-aware timestamps
     - Support for `timestamp`, `date32`, `date64`, `time32` and `time64`
     - PyArrow's behavior was consulted for edge cases
       - rounding semantics (i.e. calendar rounding happens in specified 
timezone)
       - negative values
   
   ### Are these changes tested?
   
   Yes, comprehensive test coverage includes:
   - test cases covering most(?) types, units, modes, and edge cases
     - Timezone-aware tests
     - Multi-period rounding tests
     - Half-rounding mode tests
     - Null handling and error validation tests
     - `timestamp`, `date32`, `date64`, `time32` and `time64` tests
   - Performance benchmarks
   
   ### Are there any user-facing changes?
   
   **New public API**:
   ```go
   // Functions
   compute.FloorTemporal(arr, opts)
   compute.CeilTemporal(arr, opts)
   compute.RoundTemporal(arr, opts)
   
   // Options
   compute.RoundTemporalOptions{
       Multiple: 1,
       Unit: compute.RoundTemporalMonth,
       WeekStartsMonday: true,
       CeilIsStrictlyGreater: false,
       CalendarBasedOrigin: false,
   }
   
   // Units
   compute.RoundTemporalYear, RoundTemporalQuarter, RoundTemporalMonth,
   RoundTemporalWeek, RoundTemporalDay, RoundTemporalHour,
   RoundTemporalMinute, RoundTemporalSecond, RoundTemporalMillisecond,
   RoundTemporalMicrosecond, RoundTemporalNanosecond
   ```


-- 
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]

Reply via email to