CustomBusinessHour#

class pandas::CustomBusinessHour#

pandas C++ class.

Example#

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

// Use CustomBusinessHour
CustomBusinessHour obj;
// ... operations ...

Aggregation#

Signature

Return Type

Location

Example

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

numpy::datetime64

pd_dateoffset.h:1886

View

Comparison#

Signature

Return Type

Location

Example

bool equals(const DateOffset& other) const override

bool

pd_dateoffset.h:1863

View

Iteration#

Signature

Return Type

Location

Example

int end_hour() const

int

pd_dateoffset.h:1871

Type Checking#

Signature

Return Type

Location

Example

bool is_business_day(int64_t epoch_seconds) const

bool

pd_dateoffset.h:1805

bool is_calendar_offset() const override

bool

pd_dateoffset.h:1861

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

bool

pd_dateoffset.h:1926

View

Other Methods#

Signature

Return Type

Location

Example

static int64_t epoch_day(int64_t epoch_seconds)

static int64_t

pd_dateoffset.h:1799

std::string freqstr() const override

std::string

pd_dateoffset.h:1859

View

const std::set<int64_t>& holidays() const

const std::set<int64_t>&

pd_dateoffset.h:1873

std::string name() const override

std::string

pd_dateoffset.h:1860

View

std::string repr() const override

std::string

pd_dateoffset.h:1875

View

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

numpy::datetime64

pd_dateoffset.h:1941

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

numpy::datetime64

pd_dateoffset.h:1935

int64_t snap_to_open(int64_t epoch, int direction) const

int64_t

pd_dateoffset.h:1811

int start_hour() const

int

pd_dateoffset.h:1870

uint8_t weekmask() const

uint8_t

pd_dateoffset.h:1872

View

Code Examples#

The following examples are extracted from the test suite.

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));
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 ===================================";
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;
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 ======================= ";
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;
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}
weekmask (pd_test_3_all.cpp:1377)
1367        true,
1368        "business_dates"
1369    );
1370
1371    // Should have business days (Mon-Fri = 5 days in this range)
1372    if (result.size() < 1) {
1373        std::cout << "  [FAIL] : in pd_test_3_all_bdate_range() : expected at least 1 business day" << std::endl;
1374        throw std::runtime_error("pd_test_3_all_bdate_range failed: no days returned");
1375    }
1376
1377    // Test with custom weekmask (exclude Fridays)
1378    pandas::DatetimeIndex result2 = pandas::bdate_range(
1379        "2024-01-01",
1380        "2024-01-07",  // Full week
1381        std::nullopt,
1382        "B",
1383        std::nullopt,
1384        true,
1385        "custom_days",
1386        "Mon Tue Wed Thu"  // No Fri, Sat, Sun
1387    );