MixedTzDatetimeArray#

class pandas::MixedTzDatetimeArray#

pandas C++ class.

Example#

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

// Use MixedTzDatetimeArray
MixedTzDatetimeArray obj;
// ... operations ...

Construction#

Signature

Return Type

Location

Example

static MixedTzDatetimeArray from_timestamps( const std::vector<std::optional<Timestamp>>& vec)

static MixedTzDatetimeArray

pd_mixed_tz_datetime_array.h:82

View

Indexing / Selection#

Signature

Return Type

Location

Example

const numpy::NDArray<numpy::bool_>& mask() const

const numpy::NDArray<numpy::bool_>&

pd_mixed_tz_datetime_array.h:153

View

Type Checking#

Signature

Return Type

Location

Example

bool is_na(size_t i) const

bool

pd_mixed_tz_datetime_array.h:115

View

Other Methods#

Signature

Return Type

Location

Example

const numpy::NDArray<int64_t>& data() const

const numpy::NDArray<int64_t>&

pd_mixed_tz_datetime_array.h:152

View

std::string dtype() const

std::string

pd_mixed_tz_datetime_array.h:143

View

const std::vector<std::string>& element_tz() const

const std::vector<std::string>&

pd_mixed_tz_datetime_array.h:130

const std::string& element_tz_at(size_t i) const

const std::string&

pd_mixed_tz_datetime_array.h:124

View

int64_t ns_at(size_t i) const

int64_t

pd_mixed_tz_datetime_array.h:119

size_t size() const { return data_.getSize()

size_t

pd_mixed_tz_datetime_array.h:113

View

numpy::DateTimeUnit unit() const

numpy::DateTimeUnit

pd_mixed_tz_datetime_array.h:146

View

Internal Methods#

1 internal methods (prefixed with underscore)

Code Examples#

The following examples are extracted from the test suite.

from_timestamps (pd_test_extension_array.cpp:9)
 1// pd_test_extension_array.cpp — L3 step L3.15 + Fix A storage-flip extensions
 2//
 3// Storage invariants and round-trip integrity for pandas::DatetimeArray and
 4// pandas::TimedeltaArray after the Fix A storage flip
 5// (do/plan_L3_fix_a_storage_flip.md, applied 2026-05-04).
 6//
 7// Verifies:
 8//   - sizeof(int64_t) == 8 (storage element size invariant)
 9//   - DatetimeArray::from_timestamps() round-trips a vector<optional<Timestamp>>
10//   - NaT slots are preserved through the round-trip (mask stays consistent)
11//   - tz-aware uniform-tz construction produces a non-null tz_ field
12//   - Boxing reconstruction via getElementAt() recovers the input ns values
13//   - Fix A storage shape: data() returns NDArray<int64_t> (8 B/elem, ns count)
14//   - NaT sentinel: INT64_MIN round-trips through the boxing layer
15//   - All 4 linear units (s/ms/us/ns) round-trip through ns-canonical storage
16//   - Tz-aware boxing reconstruction (UTC, US/Eastern, +05:30) preserves tz
17
18#include "../pandas/pd_datetime_array.h"
19#include "../pandas/pd_timedelta_array.h"
mask (pd_test_1_all.cpp:9119)
9109void pd_test_datetime_mixin_array_constructor() {
9110    std::cout << "========= DatetimeTDMixin array constructor =========================";
9111
9112    // Create DatetimeArray with some values
9113    numpy::NDArray<numpy::datetime64> data(std::vector<size_t>{3});
9114    data.setElementAt({0}, numpy::datetime64(1000000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2001
9115    data.setElementAt({1}, numpy::datetime64(1500000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2017
9116    data.setElementAt({2}, numpy::datetime64(1600000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2020
9117
9118    numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{3});
9119    mask.setElementAt({0}, numpy::bool_(false));
9120    mask.setElementAt({1}, numpy::bool_(false));
9121    mask.setElementAt({2}, numpy::bool_(false));
9122
9123    pandas::DatetimeArray arr(data, mask);
9124    pandas::DatetimeTDMixin idx(arr, "timestamps");
9125
9126    bool passed = (idx.size() == 3 && !idx.empty() &&
9127                   idx.name().has_value() && *idx.name() == "timestamps" &&
9128                   idx.inferred_type() == "datetime");
is_na (pd_test_1_all.cpp:51)
41    void pd_test_boolean_array_na_handling() {
42        std::cout << "========= BooleanArray: NA handling ======================= ";
43
44        pandas::BooleanArray arr({
45            std::optional<bool>(true),
46            std::nullopt,  // NA at index 1
47            std::optional<bool>(false)
48        });
49
50        if (!arr.is_na(1)) {
51            std::cout << "  [FAIL] : in pd_test_boolean_array_na_handling() : is_na(1) should be true" << std::endl;
52            throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(1) should be true");
53        }
54
55        if (arr.is_na(0)) {
56            std::cout << "  [FAIL] : in pd_test_boolean_array_na_handling() : is_na(0) should be false" << std::endl;
57            throw std::runtime_error("pd_test_boolean_array_na_handling failed: is_na(0) should be false");
58        }
59
60        if (!arr.has_na()) {
data (pd_test_1_all.cpp:9114)
9104        throw std::runtime_error("pd_test_datetime_mixin_default_constructor failed");
9105    }
9106
9107    std::cout << " -> tests passed" << std::endl;
9108}
9109
9110void pd_test_datetime_mixin_array_constructor() {
9111    std::cout << "========= DatetimeTDMixin array constructor =========================";
9112
9113    // Create DatetimeArray with some values
9114    numpy::NDArray<numpy::datetime64> data(std::vector<size_t>{3});
9115    data.setElementAt({0}, numpy::datetime64(1000000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2001
9116    data.setElementAt({1}, numpy::datetime64(1500000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2017
9117    data.setElementAt({2}, numpy::datetime64(1600000000000000000LL, numpy::DateTimeUnit::Nanosecond));  // ~2020
9118
9119    numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{3});
9120    mask.setElementAt({0}, numpy::bool_(false));
9121    mask.setElementAt({1}, numpy::bool_(false));
9122    mask.setElementAt({2}, numpy::bool_(false));
9123
9124    pandas::DatetimeArray arr(data, mask);
dtype (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;
element_tz_at (pd_test_mixed_tz_array.cpp:40)
30static int test_round_trip_mixed_tz() {
31    int errors_before = g_errors;
32    std::vector<std::optional<pandas::Timestamp>> v = {
33        pandas::Timestamp(1577836800000000000LL, "UTC"),
34        std::nullopt,
35        pandas::Timestamp(1609459200000000000LL, "US/Eastern"),
36    };
37    auto arr = pandas::MixedTzDatetimeArray::from_timestamps(v);
38    check(arr.size() == 3, "size == 3");
39    check(arr.is_na(1), "NaT slot at index 1");
40    check(arr.element_tz_at(0) == "UTC", "element_tz_at(0) == 'UTC'");
41    check(arr.element_tz_at(2) == "US/Eastern", "element_tz_at(2) == 'US/Eastern'");
42
43    auto ts0 = arr._box_func(0);
44    check(!ts0.isNaT(), "_box_func(0) is not NaT");
45    check(ts0.value() == 1577836800000000000LL, "_box_func(0) ns matches");
46
47    auto ts1 = arr._box_func(1);
48    check(ts1.isNaT(), "_box_func(1) is NaT");
49    return g_errors - errors_before;
50}
size (pd_test_1_all.cpp:22)
12#include "../pandas/pd_boolean_array.h"
13
14namespace dataframe_tests {
15
16namespace dataframe_tests_boolean_array {
17    void pd_test_boolean_array_constructors() {
18        std::cout << "========= BooleanArray: constructors ======================= ";
19
20        // Default constructor
21        pandas::BooleanArray arr1;
22        if (arr1.size() != 0) {
23            std::cout << "  [FAIL] : in pd_test_boolean_array_constructors() : default constructor size != 0" << std::endl;
24            throw std::runtime_error("pd_test_boolean_array_constructors failed: default constructor size != 0");
25        }
26
27        // Initializer list constructor
28        pandas::BooleanArray arr2({
29            std::optional<bool>(true),
30            std::optional<bool>(false),
31            std::nullopt,
32            std::optional<bool>(true)
unit (pd_test_1_all.cpp:9284)
9274    data.setElementAt({0}, numpy::datetime64(1000LL, numpy::DateTimeUnit::Nanosecond));
9275    data.setElementAt({1}, numpy::datetime64(2000LL, numpy::DateTimeUnit::Nanosecond));
9276
9277    numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{2});
9278    mask.setElementAt({0}, numpy::bool_(false));
9279    mask.setElementAt({1}, numpy::bool_(false));
9280
9281    pandas::DatetimeArray arr(data, mask);
9282    pandas::DatetimeTDMixin idx(arr);
9283
9284    std::string unit = idx.unit();
9285
9286    bool passed = (unit == "ns");  // nanosecond
9287    if (!passed) {
9288        std::cout << "  [FAIL] : in pd_test_datetime_unit_property() : unit property check failed, got '" << unit << "'" << std::endl;
9289        throw std::runtime_error("pd_test_datetime_unit_property failed");
9290    }
9291
9292    std::cout << " -> tests passed" << std::endl;
9293}