DateOffset#

class pandas::DateOffset#

pandas C++ class.

Example#

#include <pandas/pandas.h>
using namespace pandas;

// Use DateOffset
DateOffset obj;
// ... operations ...

Construction#

Signature

Return Type

Location

Example

static std::unique_ptr<DateOffset> from_freq_string(const std::string& freq)

static std::unique_ptr<DateOffset>

pd_dateoffset.h:426

View

Statistics#

Signature

Return Type

Location

Example

int minutes() const

int

pd_dateoffset.h:210

View

Aggregation#

Signature

Return Type

Location

Example

virtual numpy::datetime64 apply(const numpy::datetime64& dt) const

virtual numpy::datetime64

pd_dateoffset.h:254

View

Arithmetic#

Signature

Return Type

Location

Example

virtual int64_t add_nanos(int64_t ns) const

virtual int64_t

pd_dateoffset.h:392

View

Comparison#

Signature

Return Type

Location

Example

virtual bool equals(const DateOffset& other) const

virtual bool

pd_dateoffset.h:237

View

virtual std::unique_ptr<DateOffset> negate() const

virtual std::unique_ptr<DateOffset>

pd_dateoffset.h:247

View

Type Checking#

Signature

Return Type

Location

Example

virtual bool is_calendar_offset() const

virtual bool

pd_dateoffset.h:351

virtual bool is_on_offset(const numpy::datetime64& dt) const

virtual bool

pd_dateoffset.h:310

View

bool is_zero() const

bool

pd_dateoffset.h:404

View

Other Methods#

Signature

Return Type

Location

Example

int days() const

int

pd_dateoffset.h:208

View

numpy::datetime64 dt(ns, numpy::DateTimeUnit::Nanosecond)

numpy::datetime64

pd_dateoffset.h:380

View

numpy::datetime64 dt(ns, numpy::DateTimeUnit::Nanosecond)

numpy::datetime64

pd_dateoffset.h:393

View

virtual std::string freqstr() const

virtual std::string

pd_dateoffset.h:220

View

int hours() const

int

pd_dateoffset.h:209

View

int microseconds() const

int

pd_dateoffset.h:212

View

int months() const

int

pd_dateoffset.h:206

View

int n() const

int

pd_dateoffset.h:200

View

virtual std::string name() const

virtual std::string

pd_dateoffset.h:221

View

int nanoseconds() const

int

pd_dateoffset.h:213

View

bool normalize() const

bool

pd_dateoffset.h:202

View

static ParsedFreq parse_freq_string(const std::string& freq)

static ParsedFreq

pd_dateoffset.h:427

View

virtual std::string repr() const

virtual std::string

pd_dateoffset.h:233

View

virtual numpy::datetime64 rollback(const numpy::datetime64& dt) const

virtual numpy::datetime64

pd_dateoffset.h:321

virtual numpy::datetime64 rollforward(const numpy::datetime64& dt) const

virtual numpy::datetime64

pd_dateoffset.h:315

int seconds() const

int

pd_dateoffset.h:211

View

void set_n(int n)

void

pd_dateoffset.h:201

void set_weekday(int wd, int n)

void

pd_dateoffset.h:218

virtual int64_t snap_to_grid(int64_t ns) const

virtual int64_t

pd_dateoffset.h:372

View

virtual int64_t total_nanoseconds() const

virtual int64_t

pd_dateoffset.h:334

int weekday() const

int

pd_dateoffset.h:216

View

int weekday_n() const

int

pd_dateoffset.h:217

int weeks() const

int

pd_dateoffset.h:207

int years() const

int

pd_dateoffset.h:205

View

Code Examples#

The following examples are extracted from the test suite.

from_freq_string (pd_test_5_all.cpp:87341)
87331    auto idx = mk_idx({"2020-01-01", "2020-01-03"});
87332    auto up = idx.upsample(pandas::Day(1));
87333    pandas_tests::check(up.tz().empty(),
87334                        "case_31.tz_naive.tz_empty", local_fail);
87335}
87336
87337void f_core_05_upsample_05f4ab_case_32_overload_hourly(int& local_fail) {
87338    std::cout << "-- case_32_overload_hourly\n";
87339    auto idx = mk_idx({"2020-01-01", "2020-01-02"});
87340    auto via_string = idx.upsample("H");
87341    auto via_factory = idx.upsample(*pandas::DateOffset::from_freq_string("H"));
87342    auto a = to_ns_vec(via_string);
87343    auto b = to_ns_vec(via_factory);
87344    pandas_tests::check(a == b,
87345                        "case_32.overload_hourly.ns_vec_equal", local_fail);
87346}
87347
87348void f_core_05_upsample_05f4ab_case_33_overload_daily(int& local_fail) {
87349    std::cout << "-- case_33_overload_daily\n";
87350    auto idx = mk_idx({"2020-01-01", "2020-01-31"});
87351    auto via_string = idx.upsample("D");
minutes (pd_test_3_all.cpp:21614)
21604    }
21605    if (d.months() != 2) {
21606        throw std::runtime_error("DateOffset: months mismatch");
21607    }
21608    if (d.days() != 5) {
21609        throw std::runtime_error("DateOffset: days mismatch");
21610    }
21611    if (d.hours() != 3) {
21612        throw std::runtime_error("DateOffset: hours mismatch");
21613    }
21614    if (d.minutes() != 30) {
21615        throw std::runtime_error("DateOffset: minutes mismatch");
21616    }
21617    if (d.seconds() != 10) {
21618        throw std::runtime_error("DateOffset: seconds mismatch");
21619    }
21620
21621    std::cout << " -> tests passed" << std::endl;
21622}
21623
21624void test_yearend_freqstr() {
apply (pd_test_1_all.cpp:11244)
11234        void pd_test_func_apply_dataframe_apply_axis0() {
11235            std::cout << "========= DataFrame apply axis=0 ======================";
11236
11237            std::map<std::string, std::vector<double>> data = {
11238                {"A", {1.0, 2.0, 3.0}},
11239                {"B", {4.0, 5.0, 6.0}}
11240            };
11241            pandas::DataFrame df(data);
11242
11243            // apply axis=0 applies function to each column
11244            auto result = df.apply([](const std::vector<double>& col) {
11245                return std::accumulate(col.begin(), col.end(), 0.0);
11246            }, 0);
11247
11248            bool passed = true;
11249
11250            // Plan F·dtype: axis=0 reduce now returns a single "result" column
11251            // with the original column names ("A", "B") as the row index.
11252            // Sum of A: 1+2+3=6, Sum of B: 4+5+6=15
11253            const auto& result_col = result["result"];
11254            double sum_a = std::stod(result_col.get_value_str(0));
add_nanos (pd_test_5_all.cpp:87543)
87533    int64_t snapped = pandas::Day(1).snap_to_grid(mid.toNanoseconds());
87534    numpy::datetime64 expected("2020-01-01T00:00:00");
87535    pandas_tests::check(snapped == expected.toNanoseconds(),
87536                        "case_45.day_snap_to_grid.floors_to_midnight",
87537                        local_fail);
87538}
87539
87540void f_core_05_upsample_05f4ab_case_46_day_add_nanos(int& local_fail) {
87541    std::cout << "-- case_46_day_add_nanos\n";
87542    numpy::datetime64 start("2020-01-01T00:00:00");
87543    int64_t next_ns = pandas::Day(1).add_nanos(start.toNanoseconds());
87544    numpy::datetime64 expected("2020-01-02T00:00:00");
87545    pandas_tests::check(next_ns == expected.toNanoseconds(),
87546                        "case_46.day_add_nanos.advances_one_day",
87547                        local_fail);
87548}
87549
87550} // namespace f_test_05_datetimeindex_upsample_9_ns
87551
87552void f_test_05_datetimeindex_upsample_9() {
87553    std::cout << "========= f_test_05_datetimeindex_upsample_9 =======";
equals (pd_test_1_all.cpp:5866)
5856    std::cout << "========= equals ======================================";
5857
5858    pandas::CategoricalArray arr1({"a", "b", "a"});
5859    pandas::CategoricalArray arr2({"a", "b", "a"});
5860    pandas::CategoricalArray arr3({"a", "b", "c"});
5861
5862    pandas::CategoricalIndex idx1(arr1);
5863    pandas::CategoricalIndex idx2(arr2);
5864    pandas::CategoricalIndex idx3(arr3);
5865
5866    bool passed = (idx1.equals(idx2) && !idx1.equals(idx3));
5867    if (!passed) {
5868        std::cout << "  [FAIL] : in pd_test_categorical_index_equals()" << std::endl;
5869        throw std::runtime_error("pd_test_categorical_index_equals failed");
5870    }
5871
5872    std::cout << " -> tests passed" << std::endl;
5873}
5874
5875void pd_test_categorical_index_identical() {
5876    std::cout << "========= identical ===================================";
negate (pd_test_4_all.cpp:6343)
6333    EXPECT(static_cast<int64_t>(out[1]) == 6LL * 86400000000000LL);
6334    EXPECT(out.dtype_name() == "datetime64[ns]");
6335}
6336
6337void test_sub_dateoffset_calendar_monthend() {
6338    // 2024-01-31 in ns
6339    int64_t jan31 = 1706659200LL * 1000000000LL;
6340    auto s = make_dt_series({jan31});
6341    pandas::MonthEnd me(1);
6342    auto out = s.sub_dateoffset(me);
6343    auto neg = me.negate();
6344    auto ref = s.add_dateoffset(*neg);
6345    EXPECT(out.size() == 1);
6346    EXPECT(static_cast<int64_t>(out[0]) == static_cast<int64_t>(ref[0]));
6347    EXPECT(out.dtype_name() == "datetime64[ns]");
6348}
6349
6350void test_sub_dateoffset_equals_add_negated() {
6351    int64_t jan31 = 1706659200LL * 1000000000LL;
6352    auto s = make_dt_series({jan31, jan31 + 86400000000000LL});
6353    pandas::MonthEnd me(2);
is_on_offset (pd_test_3_all.cpp:18263)
18253void pd_test_business_day_offset() {
18254    std::cout << "========= BusinessDay offset ===========================";
18255
18256    pandas::BusinessDay offset(1);
18257    if (offset.freqstr() != "B") {
18258        std::cout << "  [FAIL] : BusinessDay freqstr() failed" << std::endl;
18259        throw std::runtime_error("pd_test_business_day_offset: freqstr() failed");
18260    }
18261
18262    // Test is_on_offset (Friday = weekday)
18263    numpy::datetime64 friday("2020-01-17");  // Friday
18264    if (!offset.is_on_offset(friday)) {
18265        std::cout << "  [FAIL] : BusinessDay is_on_offset(Friday) failed" << std::endl;
18266        throw std::runtime_error("pd_test_business_day_offset: is_on_offset(Friday) failed");
18267    }
18268
18269    // Test is_on_offset (Saturday = weekend)
18270    numpy::datetime64 saturday("2020-01-18");  // Saturday
18271    if (offset.is_on_offset(saturday)) {
18272        std::cout << "  [FAIL] : BusinessDay is_on_offset(Saturday) should be false" << std::endl;
is_zero (pd_test_1_all.cpp:4280)
4270        if (!neg[1].has_value() || !neg[1].value()) {
4271            std::cout << "  [FAIL] : -5 hours should be negative" << std::endl;
4272            throw std::runtime_error("pd_test_timedelta_array_boolean_props failed: is_negative");
4273        }
4274        if (!neg[0].has_value() || neg[0].value()) {
4275            std::cout << "  [FAIL] : 1 day should not be negative" << std::endl;
4276            throw std::runtime_error("pd_test_timedelta_array_boolean_props failed: not negative");
4277        }
4278
4279        // is_zero
4280        auto zero = arr.is_zero();
4281        if (!zero[2].has_value() || !zero[2].value()) {
4282            std::cout << "  [FAIL] : 0 seconds should be zero" << std::endl;
4283            throw std::runtime_error("pd_test_timedelta_array_boolean_props failed: is_zero");
4284        }
4285
4286        // NA should propagate
4287        if (pos[3].has_value() || neg[3].has_value() || zero[3].has_value()) {
4288            std::cout << "  [FAIL] : NaT should propagate to boolean props" << std::endl;
4289            throw std::runtime_error("pd_test_timedelta_array_boolean_props failed: NaT propagation");
4290        }
days (pd_test_1_all.cpp:4160)
4150    void pd_test_timedelta_array_component_days() {
4151        std::cout << "========= TimedeltaArray: days component ======================= ";
4152
4153        pandas::TimedeltaArray arr({
4154            std::optional<numpy::timedelta64>(numpy::timedelta64(3, numpy::DateTimeUnit::Day)),
4155            std::nullopt,
4156            std::optional<numpy::timedelta64>(numpy::timedelta64(36, numpy::DateTimeUnit::Hour))  // 1.5 days
4157        });
4158
4159        auto days_arr = arr.days();
4160
4161        auto d0 = days_arr[0];
4162        if (!d0.has_value() || d0.value() != 3) {
4163            std::cout << "  [FAIL] : days[0] should be 3" << std::endl;
4164            throw std::runtime_error("pd_test_timedelta_array_component_days failed: days[0]");
4165        }
4166
4167        auto d1 = days_arr[1];
4168        if (d1.has_value()) {
4169            std::cout << "  [FAIL] : days[1] should be NA (NaT)" << std::endl;
dt (pd_test_3_all.cpp:18239)
18229    if (offset.freqstr() != "D") {
18230        std::cout << "  [FAIL] : Day freqstr() failed" << std::endl;
18231        throw std::runtime_error("pd_test_day_offset: freqstr() failed");
18232    }
18233    if (offset.name() != "Day") {
18234        std::cout << "  [FAIL] : Day name() failed" << std::endl;
18235        throw std::runtime_error("pd_test_day_offset: name() failed");
18236    }
18237
18238    // Test apply
18239    numpy::datetime64 dt("2020-01-15");
18240    auto result = offset.apply(dt);
18241    std::tm tm = result.toTm();
18242    if (tm.tm_mday != 20) {
18243        std::cout << "  [FAIL] : Day apply() failed, got day " << tm.tm_mday << std::endl;
18244        throw std::runtime_error("pd_test_day_offset: apply() failed");
18245    }
18246
18247    std::cout << " -> tests passed" << std::endl;
18248}
dt (pd_test_3_all.cpp:18239)
18229    if (offset.freqstr() != "D") {
18230        std::cout << "  [FAIL] : Day freqstr() failed" << std::endl;
18231        throw std::runtime_error("pd_test_day_offset: freqstr() failed");
18232    }
18233    if (offset.name() != "Day") {
18234        std::cout << "  [FAIL] : Day name() failed" << std::endl;
18235        throw std::runtime_error("pd_test_day_offset: name() failed");
18236    }
18237
18238    // Test apply
18239    numpy::datetime64 dt("2020-01-15");
18240    auto result = offset.apply(dt);
18241    std::tm tm = result.toTm();
18242    if (tm.tm_mday != 20) {
18243        std::cout << "  [FAIL] : Day apply() failed, got day " << tm.tm_mday << std::endl;
18244        throw std::runtime_error("pd_test_day_offset: apply() failed");
18245    }
18246
18247    std::cout << " -> tests passed" << std::endl;
18248}
freqstr (pd_test_1_all.cpp:2671)
2661        }
2662
2663        pandas::PeriodDtype dtype_y("Y");
2664        if (dtype_y.name() != "period[Y]") {
2665            std::cout << "  [FAIL] : dtype_y.name() should be 'period[Y]'" << std::endl;
2666            throw std::runtime_error("pd_test_period_array_freq_validation failed: dtype name Y");
2667        }
2668
2669        // Test frequency string
2670        pandas::PeriodArray arr(std::vector<std::string>{"2024-01-15"}, "D");
2671        if (arr.freqstr() != "D") {
2672            std::cout << "  [FAIL] : arr.freqstr() should be 'D'" << std::endl;
2673            throw std::runtime_error("pd_test_period_array_freq_validation failed: freqstr");
2674        }
2675
2676        std::cout << " -> tests passed" << std::endl;
2677    }
2678
2679    void pd_test_period_array_year_month_quarter() {
2680        std::cout << "========= PeriodArray: year/month/quarter components ======================= ";
hours (pd_test_1_all.cpp:9567)
9557        std::cout << std::endl << "  [FAIL] : floor result incorrect";
9558        passed = false;
9559    }
9560
9561    // ceil should give 2 hours
9562    if (ceiled.total_seconds() != 7200.0) {
9563        std::cout << std::endl << "  [FAIL] : ceil result incorrect";
9564        passed = false;
9565    }
9566
9567    // round should give 2 hours (30m45s > 30m)
9568    if (rounded.total_seconds() != 7200.0) {
9569        std::cout << std::endl << "  [FAIL] : round result incorrect";
9570        passed = false;
9571    }
9572
9573    if (!passed) {
9574        throw std::runtime_error("pd_test_timedelta_rounding_params failed");
9575    }
9576
9577    std::cout << " -> tests passed" << std::endl;
microseconds (pd_test_1_all.cpp:19701)
19691    constexpr int64_t NS_PER_US = 1000LL;
19692    std::vector<std::optional<numpy::timedelta64>> values = {
19693        make_td(0),                        // 0 us
19694        make_td(500 * NS_PER_US),          // 500 us
19695        make_td(NS_PER_SEC + 100 * NS_PER_US)  // 1 sec + 100 us
19696    };
19697    pandas::TimedeltaArray arr(values);
19698    pandas::TimedeltaIndex idx(arr);
19699
19700    auto microseconds = idx.microseconds();
19701
19702    bool passed = (microseconds.size() == 3);
19703    if (!passed) {
19704        std::cout << "  [FAIL] : in pd_test_timedelta_index_microseconds()" << std::endl;
19705        throw std::runtime_error("pd_test_timedelta_index_microseconds failed");
19706    }
19707
19708    std::cout << " -> tests passed" << std::endl;
19709}
months (pd_test_3_all.cpp:21605)
21595namespace dataframe_tests {
21596namespace dataframe_tests_dateoffset_sig {
21597
21598void test_dateoffset_extra_params() {
21599    std::cout << "========= DateOffset extra parameters =============";
21600
21601    pandas::DateOffset d(1, false, 1, 2, 0, 5, 3, 30, 10, 0, 0);
21602    if (d.years() != 1) {
21603        throw std::runtime_error("DateOffset: years mismatch");
21604    }
21605    if (d.months() != 2) {
21606        throw std::runtime_error("DateOffset: months mismatch");
21607    }
21608    if (d.days() != 5) {
21609        throw std::runtime_error("DateOffset: days mismatch");
21610    }
21611    if (d.hours() != 3) {
21612        throw std::runtime_error("DateOffset: hours mismatch");
21613    }
21614    if (d.minutes() != 30) {
21615        throw std::runtime_error("DateOffset: minutes mismatch");
n (pd_test_3_all.cpp:18225)
18215namespace dataframe_tests_dateoffset {
18216
18217// ============================================================================
18218// Test Day offset
18219// ============================================================================
18220
18221void pd_test_day_offset() {
18222    std::cout << "========= Day offset ===================================";
18223
18224    pandas::Day offset(5);
18225    if (offset.n() != 5) {
18226        std::cout << "  [FAIL] : Day n() failed" << std::endl;
18227        throw std::runtime_error("pd_test_day_offset: n() failed");
18228    }
18229    if (offset.freqstr() != "D") {
18230        std::cout << "  [FAIL] : Day freqstr() failed" << std::endl;
18231        throw std::runtime_error("pd_test_day_offset: freqstr() failed");
18232    }
18233    if (offset.name() != "Day") {
18234        std::cout << "  [FAIL] : Day name() failed" << std::endl;
18235        throw std::runtime_error("pd_test_day_offset: name() failed");
name (pd_test_1_all.cpp:295)
285            throw std::runtime_error("pd_test_boolean_array_reductions failed: mean");
286        }
287
288        std::cout << " -> tests passed" << std::endl;
289    }
290
291    void pd_test_boolean_array_dtype() {
292        std::cout << "========= BooleanArray: dtype ======================= ";
293
294        pandas::BooleanArray arr;
295        if (arr.dtype().name() != "boolean") {
296            std::cout << "  [FAIL] : in pd_test_boolean_array_dtype() : dtype name should be 'boolean'" << std::endl;
297            throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype name");
298        }
299
300        if (arr.dtype().kind() != "b") {
301            std::cout << "  [FAIL] : in pd_test_boolean_array_dtype() : dtype kind should be 'b'" << std::endl;
302            throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype kind");
303        }
304
305        std::cout << " -> tests passed" << std::endl;
nanoseconds (pd_test_1_all.cpp:9379)
9369        std::cout << "  [FAIL] : in pd_test_datetime_as_unit() : as_unit check failed" << std::endl;
9370        throw std::runtime_error("pd_test_datetime_as_unit failed");
9371    }
9372
9373    std::cout << " -> tests passed" << std::endl;
9374}
9375
9376void pd_test_timedelta_as_unit() {
9377    std::cout << "========= TimedeltaTDMixin as_unit =========================";
9378
9379    // Create index in nanoseconds (1 hour, 2 hours)
9380    numpy::NDArray<numpy::timedelta64> data(std::vector<size_t>{2});
9381    data.setElementAt({0}, numpy::timedelta64(3600000000000LL, numpy::DateTimeUnit::Nanosecond));   // 1 hour
9382    data.setElementAt({1}, numpy::timedelta64(7200000000000LL, numpy::DateTimeUnit::Nanosecond));   // 2 hours
9383
9384    numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
9385    mask.setElementAt({0}, numpy::bool_(false));
9386    mask.setElementAt({1}, numpy::bool_(false));
9387
9388    pandas::TimedeltaArray arr(data, mask);
9389    pandas::TimedeltaTDMixin idx(arr, "durations");
normalize (pd_test_1_all.cpp:8723)
8713void pd_test_datetime_mixin_normalize() {
8714    std::cout << "========= normalize ===================================";
8715
8716    // Create datetime with time component
8717    std::vector<std::optional<numpy::datetime64>> values = {
8718        numpy::datetime64(86400000000000LL + 3600000000000LL, numpy::DateTimeUnit::Nanosecond)  // 1 day + 1 hour
8719    };
8720    pandas::DatetimeArray arr(values);
8721    pandas::DatetimeMixinIndex idx(arr);
8722
8723    pandas::DatetimeMixinIndex normalized = idx.normalize();
8724
8725    bool passed = (normalized.size() == 1);
8726    if (!passed) {
8727        std::cout << "  [FAIL] : in pd_test_datetime_mixin_normalize()" << std::endl;
8728        throw std::runtime_error("pd_test_datetime_mixin_normalize failed");
8729    }
8730
8731    std::cout << " -> tests passed" << std::endl;
8732}
parse_freq_string (pd_test_5_all.cpp:101264)
101254void f_core_02_freq_factory_c02f7a_case_54_yearbegin_YS_MAR(int& local_fail) {
101255    std::cout << "-- case_54_yearbegin_YS_MAR\n";
101256    check_factory_year_anchored<pandas::YearBegin>(
101257        "f_core_02_freq_factory_c02f7a_case_54.year_YS_MAR", "YS-MAR", 1, 3, local_fail);
101258}
101259
101260void f_core_02_freq_factory_c02f7a_case_55_parse_D(int& local_fail) {
101261    std::cout << "-- case_55_parse_D\n";
101262    pandas::DateOffset::ParsedFreq p =
101263        pandas::DateOffset::parse_freq_string("D");
101264    pandas_tests::check(p.n == 1,
101265        "f_core_02_freq_factory_c02f7a_case_55.parse_D.n", local_fail);
101266    pandas_tests::check(p.base == "D",
101267        "f_core_02_freq_factory_c02f7a_case_55.parse_D.base", local_fail);
101268    pandas_tests::check(p.anchor.empty(),
101269        "f_core_02_freq_factory_c02f7a_case_55.parse_D.anchor_empty", local_fail);
101270}
101271
101272void f_core_02_freq_factory_c02f7a_case_56_parse_5H(int& local_fail) {
101273    std::cout << "-- case_56_parse_5H\n";
repr (pd_test_1_all.cpp:10906)
10896    std::cout << " -> tests passed" << std::endl;
10897}
10898
10899void pd_test_extension_index_repr() {
10900    std::cout << "========= repr =========================";
10901
10902    pandas::CategoricalArray arr({"a", "b", "c"});
10903    // Use ExtensionIndex<CategoricalArray> directly to test base class repr
10904    pandas::ExtensionIndex<pandas::CategoricalArray> idx(arr, "test");
10905
10906    std::string repr_str = idx.repr();
10907
10908    bool passed = (!repr_str.empty() && repr_str.find("ExtensionIndex") != std::string::npos);
10909    if (!passed) {
10910        std::cout << "  [FAIL] : in pd_test_extension_index_repr() : repr check failed" << std::endl;
10911        throw std::runtime_error("pd_test_extension_index_repr failed");
10912    }
10913
10914    std::cout << " -> tests passed" << std::endl;
10915}
seconds (pd_test_1_all.cpp:4192)
4182    void pd_test_timedelta_array_component_seconds() {
4183        std::cout << "========= TimedeltaArray: seconds component ======================= ";
4184
4185        pandas::TimedeltaArray arr({
4186            std::optional<numpy::timedelta64>(numpy::timedelta64(90, numpy::DateTimeUnit::Second)),  // 90 secs
4187            std::optional<numpy::timedelta64>(numpy::timedelta64(3700, numpy::DateTimeUnit::Second)), // 1h + 100s
4188            std::nullopt
4189        });
4190
4191        auto secs = arr.seconds();
4192
4193        auto s0 = secs[0];
4194        if (!s0.has_value() || s0.value() != 90) {
4195            std::cout << "  [FAIL] : seconds[0] should be 90" << std::endl;
4196            throw std::runtime_error("pd_test_timedelta_array_component_seconds failed: seconds[0]");
4197        }
4198
4199        auto s1 = secs[1];
4200        if (!s1.has_value() || s1.value() != 3700) {
4201            std::cout << "  [FAIL] : seconds[1] should be 3700" << std::endl;
snap_to_grid (pd_test_5_all.cpp:87533)
87523                        "case_44.timedeltaindex_zero_freq.value_error",
87524                        local_fail);
87525    pandas_tests::check(got_msg == pandas::error_messages::kFreqZero,
87526                        "case_44.timedeltaindex_zero_freq.message",
87527                        local_fail);
87528}
87529
87530void f_core_05_upsample_05f4ab_case_45_day_snap_to_grid(int& local_fail) {
87531    std::cout << "-- case_45_day_snap_to_grid\n";
87532    numpy::datetime64 mid("2020-01-01T05:00:00");
87533    int64_t snapped = pandas::Day(1).snap_to_grid(mid.toNanoseconds());
87534    numpy::datetime64 expected("2020-01-01T00:00:00");
87535    pandas_tests::check(snapped == expected.toNanoseconds(),
87536                        "case_45.day_snap_to_grid.floors_to_midnight",
87537                        local_fail);
87538}
87539
87540void f_core_05_upsample_05f4ab_case_46_day_add_nanos(int& local_fail) {
87541    std::cout << "-- case_46_day_add_nanos\n";
87542    numpy::datetime64 start("2020-01-01T00:00:00");
87543    int64_t next_ns = pandas::Day(1).add_nanos(start.toNanoseconds());
weekday (pd_test_3_all.cpp:1471)
1461            std::cout << "  [FAIL] date_range 10-arg form: expected size 10, got "
1462                      << idx.size() << std::endl;
1463            throw std::runtime_error("date_range 10-arg form regressed");
1464        }
1465    }
1466
1467    std::cout << " -> tests passed" << std::endl;
1468}
1469
1470void pd_test_3_all_period_weekday() {
1471    std::cout << "========= PeriodArray.weekday() ======================";
1472
1473    // Create a PeriodArray with some dates
1474    std::vector<std::optional<numpy::int64>> ordinals = {0, 1, 2, 3, 4};  // Days from epoch
1475    pandas::PeriodArray arr(ordinals, "D");
1476
1477    pandas::IntegerArray<numpy::int32> weekdays = arr.weekday();
1478
1479    if (weekdays.size() != 5) {
1480        std::cout << "  [FAIL] : in pd_test_3_all_period_weekday() : size should be 5" << std::endl;
1481        throw std::runtime_error("pd_test_3_all_period_weekday failed: size");
years (pd_test_3_all.cpp:21602)
21592#include <stdexcept>
21593#include <string>
21594
21595namespace dataframe_tests {
21596namespace dataframe_tests_dateoffset_sig {
21597
21598void test_dateoffset_extra_params() {
21599    std::cout << "========= DateOffset extra parameters =============";
21600
21601    pandas::DateOffset d(1, false, 1, 2, 0, 5, 3, 30, 10, 0, 0);
21602    if (d.years() != 1) {
21603        throw std::runtime_error("DateOffset: years mismatch");
21604    }
21605    if (d.months() != 2) {
21606        throw std::runtime_error("DateOffset: months mismatch");
21607    }
21608    if (d.days() != 5) {
21609        throw std::runtime_error("DateOffset: days mismatch");
21610    }
21611    if (d.hours() != 3) {
21612        throw std::runtime_error("DateOffset: hours mismatch");