lidavidm commented on a change in pull request #11818:
URL: https://github.com/apache/arrow/pull/11818#discussion_r778089595
##########
File path: python/pyarrow/tests/test_compute.py
##########
@@ -1899,6 +1900,71 @@ def test_assume_timezone():
result.equals(pa.array(expected))
+def _check_temporal_rounding(ts, values, unit):
+ unit_shorthand = {
+ "nanosecond": "ns",
+ "microsecond": "us",
+ "millisecond": "L",
+ "second": "s",
+ "minute": "min",
+ "hour": "H",
+ "day": "D"
+ }
+ ta = pa.array(ts)
+
+ for value in values:
+ frequency = str(value) + unit_shorthand[unit]
+ options = pc.RoundTemporalOptions(value, unit)
+
+ result = pc.ceil_temporal(ta, options=options).to_pandas()
+ expected = ts.dt.ceil(frequency)
+ if unit != "nanosecond":
Review comment:
What's the difference with Pandas here?
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc
##########
@@ -452,6 +474,296 @@ struct Nanosecond {
}
};
+// ----------------------------------------------------------------------
+// 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 ymd{floor<days>(localizer_.template
ConvertTimePoint<Duration>(arg))};
+
+ if (multiple == 1) {
+ return year_month_day(ymd.year() / ymd.month() / 1);
+ } else {
+ int32_t total_months_origin = 1970 * 12;
+ int32_t total_months = static_cast<int32_t>(ymd.year()) * 12 +
+
static_cast<int32_t>(static_cast<uint32_t>(ymd.month())) - 1 -
+ total_months_origin;
+
+ if (total_months >= 0) {
+ total_months = total_months / multiple * multiple;
+ } else {
+ total_months = (total_months - multiple + 1) / multiple * multiple;
+ }
+ return year_month_day(year{1970} / jan / 0) + months{total_months};
+ }
+}
+
+template <typename Duration, typename Unit, typename Localizer>
+const Duration FloorTimePoint(const int64_t arg, const int64_t multiple,
+ Localizer localizer_, Status* st) {
+ const auto t = localizer_.template ConvertTimePoint<Duration>(arg);
+ const Unit d = floor<Unit>(t.time_since_epoch());
+
+ if (multiple == 1) {
+ return localizer_.template
ConvertLocalToSys<Duration>(duration_cast<Duration>(d),
+ st);
+ } else {
+ const Unit unit = Unit{multiple};
+ auto m = (d.count() >= 0) ? d / unit * unit : (d - unit + Unit{1}) / unit
* unit;
+ return localizer_.template
ConvertLocalToSys<Duration>(duration_cast<Duration>(m),
+ st);
+ }
+}
+
+template <typename Duration, typename Unit, typename Localizer>
+Duration CeilTimePoint(const int64_t arg, const int64_t multiple, Localizer
localizer_,
+ Status* st) {
+ const Duration result =
+ FloorTimePoint<Duration, Unit, Localizer>(arg, multiple, localizer_, st);
+ const auto c =
+ localizer_.template
ConvertTimePoint<Duration>(result.count()).time_since_epoch() +
+ duration_cast<Duration>(Unit{multiple});
+ return localizer_.template
ConvertLocalToSys<Duration>(duration_cast<Duration>(c), st);
+}
+
+template <typename Duration, typename Unit, typename Localizer>
+Duration RoundTimePoint(const int64_t arg, const int64_t multiple, Localizer
localizer_,
+ Status* st) {
+ const Duration f =
+ FloorTimePoint<Duration, Unit, Localizer>(arg, multiple, localizer_, st);
+ const Duration c =
+ CeilTimePoint<Duration, Unit, Localizer>(arg, multiple, localizer_, st);
+ return (Duration{arg} - f > c - Duration{arg}) ? c : f;
+}
+
+template <typename Duration, typename Localizer>
+struct CeilTemporal {
+ explicit CeilTemporal(const RoundTemporalOptions* options, Localizer&&
localizer)
+ : localizer_(std::move(localizer)), options(*options) {}
+
+ template <typename T, typename Arg0>
+ T Call(KernelContext*, Arg0 arg, Status* st) const {
+ Duration t;
+ switch (options.unit) {
+ case compute::CalendarUnit::NANOSECOND:
+ t = CeilTimePoint<Duration, std::chrono::nanoseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MICROSECOND:
+ t = CeilTimePoint<Duration, std::chrono::microseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MILLISECOND:
+ t = CeilTimePoint<Duration, std::chrono::milliseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::SECOND:
+ t = CeilTimePoint<Duration, std::chrono::seconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MINUTE:
+ t = CeilTimePoint<Duration, minutes, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::HOUR:
+ t = CeilTimePoint<Duration, std::chrono::hours, Localizer>(arg,
options.multiple,
+ localizer_,
st);
+ break;
+ case compute::CalendarUnit::DAY:
+ t = CeilTimePoint<Duration, days, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::WEEK:
+ t = CeilTimePoint<Duration, weeks, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::MONTH: {
+ year_month_day ymd =
+ GetFlooredYmd<Duration, Localizer>(arg, options.multiple,
localizer_);
+ ymd += months{options.multiple};
+ t = localizer_.ConvertDays(ymd.year() / ymd.month() /
1).time_since_epoch();
+ break;
+ }
+ case compute::CalendarUnit::QUARTER: {
+ year_month_day ymd =
+ GetFlooredYmd<Duration, Localizer>(arg, 3 * options.multiple,
localizer_);
+ ymd += months{3 * options.multiple};
+ t = localizer_.ConvertDays(ymd.year() / ymd.month() /
1).time_since_epoch();
+ break;
+ }
+ case compute::CalendarUnit::YEAR: {
+ year_month_day ymd(
+ floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)));
+ year y{(static_cast<int32_t>(ymd.year()) / options.multiple + 1) *
+ options.multiple};
+ t = localizer_.ConvertDays(y / jan / 1).time_since_epoch();
+ break;
+ }
+ default:
+ t = Duration{arg};
+ }
+ return static_cast<T>(t.count());
+ }
+
+ Localizer localizer_;
+ RoundTemporalOptions options;
+};
+
+template <typename Duration, typename Localizer>
+struct FloorTemporal {
+ explicit FloorTemporal(const RoundTemporalOptions* options, Localizer&&
localizer)
+ : localizer_(std::move(localizer)), options(*options) {}
+
+ template <typename T, typename Arg0>
+ T Call(KernelContext*, Arg0 arg, Status* st) const {
+ Duration t;
+ switch (options.unit) {
+ case compute::CalendarUnit::NANOSECOND:
+ t = FloorTimePoint<Duration, std::chrono::nanoseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MICROSECOND:
+ t = FloorTimePoint<Duration, std::chrono::microseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MILLISECOND:
+ t = FloorTimePoint<Duration, std::chrono::milliseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::SECOND:
+ t = FloorTimePoint<Duration, std::chrono::seconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MINUTE:
+ t = FloorTimePoint<Duration, minutes, Localizer>(arg, options.multiple,
+ localizer_, st);
+ break;
+ case compute::CalendarUnit::HOUR:
+ t = FloorTimePoint<Duration, std::chrono::hours, Localizer>(arg,
options.multiple,
+
localizer_, st);
+ break;
+ case compute::CalendarUnit::DAY:
+ t = FloorTimePoint<Duration, days, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::WEEK:
+ t = FloorTimePoint<Duration, weeks, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::MONTH: {
+ year_month_day ymd =
+ GetFlooredYmd<Duration, Localizer>(arg, options.multiple,
localizer_);
+ t = localizer_.ConvertDays(ymd.year() / ymd.month() /
1).time_since_epoch();
+ break;
+ }
+ case compute::CalendarUnit::QUARTER: {
+ year_month_day ymd =
+ GetFlooredYmd<Duration, Localizer>(arg, 3 * options.multiple,
localizer_);
+ t = localizer_.ConvertDays(ymd.year() / ymd.month() /
1).time_since_epoch();
+ break;
+ }
+ case compute::CalendarUnit::YEAR: {
+ year_month_day ymd(
+ floor<days>(localizer_.template ConvertTimePoint<Duration>(arg)));
+ year y{(static_cast<int32_t>(ymd.year()) / options.multiple) *
options.multiple};
+ t = localizer_.ConvertDays(y / jan / 1).time_since_epoch();
+ break;
+ }
+ default:
+ t = Duration{arg};
+ }
+ return static_cast<T>(t.count());
+ }
+
+ Localizer localizer_;
+ RoundTemporalOptions options;
+};
+
+template <typename Duration, typename Localizer>
+struct RoundTemporal {
+ explicit RoundTemporal(const RoundTemporalOptions* options, Localizer&&
localizer)
+ : localizer_(std::move(localizer)), options(*options) {}
+
+ template <typename T, typename Arg0>
+ T Call(KernelContext*, Arg0 arg, Status* st) const {
+ Duration t;
+ switch (options.unit) {
+ case compute::CalendarUnit::NANOSECOND:
+ t = RoundTimePoint<Duration, std::chrono::nanoseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MICROSECOND:
+ t = RoundTimePoint<Duration, std::chrono::microseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MILLISECOND:
+ t = RoundTimePoint<Duration, std::chrono::milliseconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::SECOND:
+ t = RoundTimePoint<Duration, std::chrono::seconds, Localizer>(
+ arg, options.multiple, localizer_, st);
+ break;
+ case compute::CalendarUnit::MINUTE:
+ t = RoundTimePoint<Duration, minutes, Localizer>(arg, options.multiple,
+ localizer_, st);
+ break;
+ case compute::CalendarUnit::HOUR:
+ t = RoundTimePoint<Duration, std::chrono::hours, Localizer>(arg,
options.multiple,
+
localizer_, st);
+ break;
+ case compute::CalendarUnit::DAY:
+ t = RoundTimePoint<Duration, days, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::WEEK:
+ t = RoundTimePoint<Duration, weeks, Localizer>(arg, options.multiple,
localizer_,
+ st);
+ break;
+ case compute::CalendarUnit::MONTH: {
+ auto t0 = localizer_.template ConvertTimePoint<Duration>(arg);
+ year_month_day ymd =
+ GetFlooredYmd<Duration, Localizer>(arg, options.multiple,
localizer_);
+
+ auto f = localizer_.ConvertDays(ymd.year() / ymd.month() / 1);
+ ymd += months{options.multiple};
+ auto c = localizer_.ConvertDays(ymd.year() / ymd.month() / 1);
+
+ t = (t0 - f > c - t0) ? c.time_since_epoch() : f.time_since_epoch();
Review comment:
Just curious, should this be `>=`?
##########
File path: cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
##########
@@ -1324,6 +1357,578 @@ TEST_F(ScalarTemporalTest, TestTemporalDifferenceZoned)
{
}
}
+TEST_F(ScalarTemporalTest, TestCeilTemporal) {
+ std::string op = "ceil_temporal";
+ const char* ceil_1_nanosecond =
+ R"(["1970-01-01 00:00:59.123456789", "2000-02-29 23:23:23.999999999",
+ "1899-01-01 00:59:20.001001001", "2033-05-18 03:33:20.000000000",
+ "2020-01-01 01:05:05.001000000", "2019-12-31 02:10:10.002000000",
+ "2019-12-30 03:15:15.003000000", "2009-12-31 04:20:20.004132000",
+ "2010-01-01 05:25:25.005321000", "2010-01-03 06:30:30.006163000",
+ "2010-01-04 07:35:35.000000000", "2006-01-01 08:40:40.000000000",
+ "2005-12-31 09:45:45.000000000", "2008-12-28 00:00:00.000000000",
+ "2008-12-29 00:00:00.000000000", "2012-01-01 01:02:03.000000000",
null])";
+ const char* ceil_1_microsecond =
+ R"(["1970-01-01 00:00:59.123457", "2000-02-29 23:23:24.000000",
+ "1899-01-01 00:59:20.001002", "2033-05-18 03:33:20.000000",
+ "2020-01-01 01:05:05.001000", "2019-12-31 02:10:10.002000",
+ "2019-12-30 03:15:15.003000", "2009-12-31 04:20:20.004132",
+ "2010-01-01 05:25:25.005321", "2010-01-03 06:30:30.006163",
+ "2010-01-04 07:35:35.000000", "2006-01-01 08:40:40.000000",
+ "2005-12-31 09:45:45.000000", "2008-12-28 00:00:00.000000",
+ "2008-12-29 00:00:00.000000", "2012-01-01 01:02:03.000000", null])";
+ const char* ceil_1_millisecond =
+ R"(["1970-01-01 00:00:59.124", "2000-02-29 23:23:24.000",
+ "1899-01-01 00:59:20.002", "2033-05-18 03:33:20.000",
+ "2020-01-01 01:05:05.001", "2019-12-31 02:10:10.002",
+ "2019-12-30 03:15:15.003", "2009-12-31 04:20:20.005",
+ "2010-01-01 05:25:25.006", "2010-01-03 06:30:30.007",
+ "2010-01-04 07:35:35.000", "2006-01-01 08:40:40.000",
+ "2005-12-31 09:45:45.000", "2008-12-28 00:00:00.000",
+ "2008-12-29 00:00:00.000", "2012-01-01 01:02:03.000", null])";
+ const char* ceil_1_second =
+ R"(["1970-01-01 00:01:00", "2000-02-29 23:23:24", "1899-01-01 00:59:21",
+ "2033-05-18 03:33:20", "2020-01-01 01:05:06", "2019-12-31 02:10:11",
+ "2019-12-30 03:15:16", "2009-12-31 04:20:21", "2010-01-01 05:25:26",
+ "2010-01-03 06:30:31", "2010-01-04 07:35:35", "2006-01-01 08:40:40",
+ "2005-12-31 09:45:45", "2008-12-28 00:00:00", "2008-12-29 00:00:00",
+ "2012-01-01 01:02:03", null])";
+ const char* ceil_1_minute =
+ R"(["1970-01-01 00:01:00", "2000-02-29 23:24:00", "1899-01-01 01:00:00",
+ "2033-05-18 03:34:00", "2020-01-01 01:06:00", "2019-12-31 02:11:00",
+ "2019-12-30 03:16:00", "2009-12-31 04:21:00", "2010-01-01 05:26:00",
+ "2010-01-03 06:31:00", "2010-01-04 07:36:00", "2006-01-01 08:41:00",
+ "2005-12-31 09:46:00", "2008-12-28 00:00:00", "2008-12-29 00:00:00",
+ "2012-01-01 01:03:00", null])";
+ const char* ceil_1_hour =
+ R"(["1970-01-01 01:00:00", "2000-03-01 00:00:00", "1899-01-01 01:00:00",
+ "2033-05-18 04:00:00", "2020-01-01 02:00:00", "2019-12-31 03:00:00",
+ "2019-12-30 04:00:00", "2009-12-31 05:00:00", "2010-01-01 06:00:00",
+ "2010-01-03 07:00:00", "2010-01-04 08:00:00", "2006-01-01 09:00:00",
+ "2005-12-31 10:00:00", "2008-12-28 00:00:00", "2008-12-29 00:00:00",
+ "2012-01-01 02:00:00", null])";
+ const char* ceil_1_day =
+ R"(["1970-01-02", "2000-03-01", "1899-01-02", "2033-05-19", "2020-01-02",
+ "2020-01-01", "2019-12-31", "2010-01-01", "2010-01-02", "2010-01-04",
+ "2010-01-05", "2006-01-02", "2006-01-01", "2008-12-28", "2008-12-29",
+ "2012-01-02", null])";
+ const char* ceil_1_weeks =
+ R"(["1970-01-08", "2000-03-02", "1899-01-05", "2033-05-19", "2020-01-02",
+ "2020-01-02", "2020-01-02", "2010-01-07", "2010-01-07", "2010-01-07",
+ "2010-01-07", "2006-01-05", "2006-01-05", "2009-01-01", "2009-01-01",
+ "2012-01-05", null])";
+ const char* ceil_1_months =
+ R"(["1970-02-01", "2000-03-01", "1899-02-01", "2033-06-01", "2020-02-01",
+ "2020-01-01", "2020-01-01", "2010-01-01", "2010-02-01", "2010-02-01",
+ "2010-02-01", "2006-02-01", "2006-01-01", "2009-01-01", "2009-01-01",
+ "2012-02-01", null])";
+ const char* ceil_1_quarters =
+ R"(["1970-04-01", "2000-04-01", "1899-04-01", "2033-07-01", "2020-04-01",
+ "2020-01-01", "2020-01-01", "2010-01-01", "2010-04-01", "2010-04-01",
+ "2010-04-01", "2006-04-01", "2006-01-01", "2009-01-01", "2009-01-01",
+ "2012-04-01", null])";
+ const char* ceil_1_years =
+ R"(["1971-01-01", "2001-01-01", "1900-01-01", "2034-01-01", "2021-01-01",
+ "2020-01-01", "2020-01-01", "2010-01-01", "2011-01-01", "2011-01-01",
+ "2011-01-01", "2007-01-01", "2006-01-01", "2009-01-01", "2009-01-01",
+ "2013-01-01", null])";
+ const char* ceil_15_nanosecond =
+ R"(["1970-01-01 00:00:59.123456790", "2000-02-29 23:23:24.000000000",
+ "1899-01-01 00:59:20.001001005", "2033-05-18 03:33:20.000000010",
+ "2020-01-01 01:05:05.001000000", "2019-12-31 02:10:10.002000000",
+ "2019-12-30 03:15:15.003000000", "2009-12-31 04:20:20.004132000",
+ "2010-01-01 05:25:25.005321000", "2010-01-03 06:30:30.006163005",
+ "2010-01-04 07:35:35.000000010", "2006-01-01 08:40:40.000000005",
+ "2005-12-31 09:45:45.000000000", "2008-12-28 00:00:00.000000000",
+ "2008-12-29 00:00:00.000000000", "2012-01-01 01:02:03.000000000",
null])";
+ const char* ceil_15_microsecond =
+ R"(["1970-01-01 00:00:59.123460", "2000-02-29 23:23:24.000000",
+ "1899-01-01 00:59:20.001015", "2033-05-18 03:33:20.000010",
+ "2020-01-01 01:05:05.001000", "2019-12-31 02:10:10.002000",
+ "2019-12-30 03:15:15.003000", "2009-12-31 04:20:20.004135",
+ "2010-01-01 05:25:25.005330", "2010-01-03 06:30:30.006165",
+ "2010-01-04 07:35:35.000010", "2006-01-01 08:40:40.000005",
+ "2005-12-31 09:45:45.000000", "2008-12-28 00:00:00.000000",
+ "2008-12-29 00:00:00.000000", "2012-01-01 01:02:03.000000", null])";
+ const char* ceil_15_millisecond =
+ R"(["1970-01-01 00:00:59.130", "2000-02-29 23:23:24.000",
+ "1899-01-01 00:59:20.010", "2033-05-18 03:33:20.010",
+ "2020-01-01 01:05:05.010", "2019-12-31 02:10:10.005",
+ "2019-12-30 03:15:15.015", "2009-12-31 04:20:20.010",
+ "2010-01-01 05:25:25.020", "2010-01-03 06:30:30.015",
+ "2010-01-04 07:35:35.010", "2006-01-01 08:40:40.005",
+ "2005-12-31 09:45:45.000", "2008-12-28 00:00:00.000",
+ "2008-12-29 00:00:00.000", "2012-01-01 01:02:03.000", null])";
+ const char* ceil_15_second =
+ R"(["1970-01-01 00:01:00", "2000-02-29 23:23:30", "1899-01-01 00:59:30",
+ "2033-05-18 03:33:30", "2020-01-01 01:05:15", "2019-12-31 02:10:15",
+ "2019-12-30 03:15:30", "2009-12-31 04:20:30", "2010-01-01 05:25:30",
+ "2010-01-03 06:30:45", "2010-01-04 07:35:45", "2006-01-01 08:40:45",
+ "2005-12-31 09:45:45", "2008-12-28 00:00:00", "2008-12-29 00:00:00",
+ "2012-01-01 01:02:15", null])";
+ const char* ceil_15_minute =
+ R"(["1970-01-01 00:15:00", "2000-02-29 23:30:00", "1899-01-01 01:00:00",
+ "2033-05-18 03:45:00", "2020-01-01 01:15:00", "2019-12-31 02:15:00",
+ "2019-12-30 03:30:00", "2009-12-31 04:30:00", "2010-01-01 05:30:00",
+ "2010-01-03 06:45:00", "2010-01-04 07:45:00", "2006-01-01 08:45:00",
+ "2005-12-31 10:00:00", "2008-12-28 00:00:00", "2008-12-29 00:00:00",
+ "2012-01-01 01:15:00", null])";
+ const char* ceil_15_hour =
+ R"(["1970-01-01 15:00:00", "2000-03-01 12:00:00", "1899-01-01 03:00:00",
+ "2033-05-18 18:00:00", "2020-01-01 12:00:00", "2019-12-31 06:00:00",
+ "2019-12-30 15:00:00", "2009-12-31 09:00:00", "2010-01-01 15:00:00",
+ "2010-01-03 12:00:00", "2010-01-04 18:00:00", "2006-01-01 09:00:00",
+ "2005-12-31 18:00:00", "2008-12-28 06:00:00", "2008-12-29 12:00:00",
+ "2012-01-01 15:00:00", null])";
+ const char* ceil_15_day =
+ R"(["1970-01-16", "2000-03-09", "1899-01-13", "2033-05-30", "2020-01-09",
+ "2020-01-09", "2020-01-09", "2010-01-01", "2010-01-16", "2010-01-16",
+ "2010-01-16", "2006-01-07", "2006-01-07", "2009-01-06", "2009-01-06",
+ "2012-01-06", null])";
+ const char* ceil_15_weeks =
+ R"(["1970-04-16", "2000-03-09", "1899-04-13", "2033-07-14", "2020-01-09",
+ "2020-01-09", "2020-01-09", "2010-04-01", "2010-04-01", "2010-04-01",
+ "2010-04-01", "2006-03-23", "2006-03-23", "2009-02-05", "2009-02-05",
+ "2012-04-05", null])";
+ const char* ceil_15_months =
+ R"(["1971-04-01", "2001-04-01", "1900-01-01", "2033-10-01", "2021-04-01",
+ "2020-01-01", "2020-01-01", "2010-01-01", "2011-04-01", "2011-04-01",
+ "2011-04-01", "2006-04-01", "2006-04-01", "2010-01-01", "2010-01-01",
+ "2012-07-01", null])";
+ const char* ceil_15_quarters =
+ R"(["1973-10-01", "2003-10-01", "1902-07-01", "2033-10-01", "2022-07-01",
+ "2022-07-01", "2022-07-01", "2011-04-01", "2011-04-01", "2011-04-01",
+ "2011-04-01", "2007-07-01", "2007-07-01", "2011-04-01", "2011-04-01",
+ "2015-01-01", null])";
+ const char* ceil_15_years =
+ R"(["1980-01-01", "2010-01-01", "1905-01-01", "2040-01-01", "2025-01-01",
+ "2025-01-01", "2025-01-01", "2010-01-01", "2025-01-01", "2025-01-01",
+ "2025-01-01", "2010-01-01", "2010-01-01", "2010-01-01", "2010-01-01",
+ "2025-01-01", null])";
+
+ auto unit = timestamp(TimeUnit::NANO, "UTC");
+// CheckScalarUnary(op, unit, times, unit, ceil_1_nanosecond,
&round_to_1_nanoseconds);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_microsecond,
&round_to_1_microseconds);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_millisecond,
&round_to_1_milliseconds);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_second,
&round_to_1_seconds);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_minute,
&round_to_1_minutes);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_hour, &round_to_1_hours);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_day, &round_to_1_days);
+// CheckScalarUnary(op, unit, times, unit, ceil_1_weeks, &round_to_1_weeks);
Review comment:
There's commented out tests here too.
##########
File path: python/pyarrow/tests/test_compute.py
##########
@@ -1899,6 +1900,71 @@ def test_assume_timezone():
result.equals(pa.array(expected))
+def _check_temporal_rounding(ts, values, unit):
+ unit_shorthand = {
+ "nanosecond": "ns",
+ "microsecond": "us",
+ "millisecond": "L",
+ "second": "s",
+ "minute": "min",
+ "hour": "H",
+ "day": "D"
+ }
+ ta = pa.array(ts)
+
+ for value in values:
+ frequency = str(value) + unit_shorthand[unit]
+ options = pc.RoundTemporalOptions(value, unit)
+
+ result = pc.ceil_temporal(ta, options=options).to_pandas()
+ expected = ts.dt.ceil(frequency)
+ if unit != "nanosecond":
+ np.testing.assert_array_equal(result, expected)
+
+ result = pc.floor_temporal(ta, options=options).to_pandas()
+ expected = ts.dt.floor(frequency)
+ np.testing.assert_array_equal(result, expected)
+
+ result = pc.round_temporal(ta, options=options).to_pandas()
+ expected = ts.dt.round(frequency)
+ np.testing.assert_array_equal(result, expected)
+
+
+# TODO: We should test on windows once ARROW-13168 is resolved.
[email protected](sys.platform == 'win32',
+ reason="Timezone database is not available on Windows yet")
[email protected]('unit', ("nanosecond", "microsecond", "millisecond",
+ "second", "minute", "hour", "day"))
[email protected]
+def test_round_temporal(unit):
+ values = (1, 2, 3, 4, 5, 6, 7, 10, 15, 24, 60, 250, 500, 750)
+ timestamps = [
+ # "1899-04-18 01:57:09.190202880",
+ # "1899-09-12 07:03:30.080325120",
+ # "1904-06-21 20:55:36.493869056",
Review comment:
Are these still meant to be commented out?
--
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]