FillValue#

class pandas::FillValue#

pandas C++ class.

Example#

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

// Use FillValue
FillValue obj;
// ... operations ...

Other Methods#

Signature

Return Type

Location

Example

static FillValue na()

static FillValue

pd_func_dispatch.h:329

View

static FillValue nan()

static FillValue

pd_func_dispatch.h:328

View

static FillValue nat()

static FillValue

pd_func_dispatch.h:330

View

static FillValue none()

static FillValue

pd_func_dispatch.h:331

View

static FillValue of_bool(bool v)

static FillValue

pd_func_dispatch.h:324

View

static FillValue of_numeric(double v)

static FillValue

pd_func_dispatch.h:318

View

static FillValue of_numeric_int(double v)

static FillValue

pd_func_dispatch.h:323

View

static FillValue of_string(std::string v) { FillValue fv

static FillValue

pd_func_dispatch.h:325

View

static FillValue of_timedelta_ns(std::int64_t v)

static FillValue

pd_func_dispatch.h:327

View

static FillValue of_timestamp_ns(std::int64_t v)

static FillValue

pd_func_dispatch.h:326

View

Code Examples#

The following examples are extracted from the test suite.

na (pd_test_1_all.cpp:84)
74    void pd_test_boolean_array_kleene_and() {
75        std::cout << "========= BooleanArray: Kleene AND ======================= ";
76
77        // Kleene AND truth table:
78        // T & T = T, T & F = F, T & NA = NA
79        // F & T = F, F & F = F, F & NA = F (False dominates)
80        // NA & T = NA, NA & F = F, NA & NA = NA
81
82        pandas::BooleanArray t({std::optional<bool>(true)});
83        pandas::BooleanArray f({std::optional<bool>(false)});
84        pandas::BooleanArray na({std::nullopt});
85
86        // T & T = T
87        auto tt = (t & t);
88        if (!tt[0].has_value() || !tt[0].value()) {
89            std::cout << "  [FAIL] : in pd_test_boolean_array_kleene_and() : T & T should be T" << std::endl;
90            throw std::runtime_error("pd_test_boolean_array_kleene_and failed: T & T");
91        }
92
93        // T & F = F
94        auto tf = (t & f);
nan (pd_test_1_all.cpp:1556)
1546        std::cout << " -> tests passed" << std::endl;
1547    }
1548
1549    void pd_test_floating_array_nan_conversion() {
1550        std::cout << "========= FloatingArray: NaN to NA conversion ======================= ";
1551
1552        // NaN values should be automatically converted to NA
1553        pandas::FloatingArray<double> arr({
1554            std::optional<double>(1.0),
1555            std::optional<double>(std::nan("")),  // NaN
1556            std::optional<double>(3.0)
1557        });
1558
1559        if (!arr.is_na(1)) {
1560            std::cout << "  [FAIL] : in pd_test_floating_array_nan_conversion() : NaN should be converted to NA" << std::endl;
1561            throw std::runtime_error("pd_test_floating_array_nan_conversion failed: NaN should be NA");
1562        }
1563
1564        if (arr.is_na(0) || arr.is_na(2)) {
1565            std::cout << "  [FAIL] : in pd_test_floating_array_nan_conversion() : non-NaN should not be NA" << std::endl;
nat (pd_test_5_all.cpp:97717)
97707    std::string result_override;
97708    std::string variant_label;
97709};
97710
97711static pandas::FillValue fv_none()         { return pandas::FillValue::none(); }
97712
97713static pandas::FillValue fv_nan()          { return pandas::FillValue::nan(); }
97714
97715static pandas::FillValue fv_na()           { return pandas::FillValue::na(); }
97716
97717static pandas::FillValue fv_nat()          { return pandas::FillValue::nat(); }
97718
97719static pandas::FillValue fv_bool_false()   { return pandas::FillValue::of_bool(false); }
97720
97721static pandas::FillValue fv_num_zero()     { return pandas::FillValue::of_numeric(0.0); }
97722
97723static pandas::FillValue fv_string_x()     { return pandas::FillValue::of_string("x"); }
97724
97725static Probe probe_result(pandas::Result& r) {
97726    Probe p;
97727    std::visit([&](auto& alt) {
none (pd_test_5_all.cpp:90413)
90403                                    pandas::FillValue::of_bool(true));
90404        (void)r;
90405    }, local_fail);
90406}
90407
90408static void f_20_847312_dispatch_complex_none(int& local_fail) {
90409    std::cout << "-- f_20_847312_dispatch_complex_none\n";
90410    expect_value_error_duplicate("c12_dispatch_complex_none", [] {
90411        auto s = make_series<cplx>({{1, 2}, {3, 4}, {5, 6}}, {"c1", "c1", "c2"});
90412        auto r = s.reindex_dispatch({"c1", "c2", "c3"}, "",
90413                                    pandas::FillValue::none());
90414        (void)r;
90415    }, local_fail);
90416}
90417
90418static void f_20_847313_df_dup_rows_axis0(int& local_fail) {
90419    std::cout << "-- f_20_847313_df_dup_rows_axis0\n";
90420    expect_value_error_duplicate("c13_df_dup_rows_axis0", [] {
90421        std::vector<pandas::Series<std::int64_t>> cols;
90422        cols.emplace_back(std::vector<std::int64_t>{10, 20, 30});
90423        cols.emplace_back(std::vector<std::int64_t>{40, 50, 60});
of_bool (pd_test_5_all.cpp:90403)
90393                                    pandas::FillValue::of_numeric(nan));
90394        (void)r;
90395    }, local_fail);
90396}
90397
90398static void f_20_847311_dispatch_int64_bool_fill(int& local_fail) {
90399    std::cout << "-- f_20_847311_dispatch_int64_bool_fill\n";
90400    expect_value_error_duplicate("c11_dispatch_int64_bool", [] {
90401        auto s = make_series<std::int64_t>({1, 2, 3}, {"a", "a", "b"});
90402        auto r = s.reindex_dispatch({"a", "b", "c"}, "",
90403                                    pandas::FillValue::of_bool(true));
90404        (void)r;
90405    }, local_fail);
90406}
90407
90408static void f_20_847312_dispatch_complex_none(int& local_fail) {
90409    std::cout << "-- f_20_847312_dispatch_complex_none\n";
90410    expect_value_error_duplicate("c12_dispatch_complex_none", [] {
90411        auto s = make_series<cplx>({{1, 2}, {3, 4}, {5, 6}}, {"c1", "c1", "c2"});
90412        auto r = s.reindex_dispatch({"c1", "c2", "c3"}, "",
90413                                    pandas::FillValue::none());
of_numeric (pd_test_5_all.cpp:61047)
61037    return out;
61038}
61039
61040template <typename T>
61041static std::pair<std::string, std::string>
61042run_numeric_fill_lt29(const std::vector<T>& vals,
61043                      const std::vector<std::string>& new_idx,
61044                      double fill) {
61045    auto s = make_series_with_idx_lt29<T>(vals, src_idx_for_lt29(vals.size()));
61046    pandas::Result r = s.reindex_dispatch(
61047        new_idx, "", pandas::FillValue::of_numeric(fill));
61048
61049    if (std::holds_alternative<
61050            std::unique_ptr<pandas::Series<std::string>>>(r.value)) {
61051        auto& sp = std::get<
61052            std::unique_ptr<pandas::Series<std::string>>>(r.value);
61053        auto df = sp->to_frame(std::optional<std::string>("v"));
61054        auto dts = df.dtypes();
61055        return {df.to_string(),
61056                dts.empty() ? std::string("<no col>") : dts[0]};
61057    }
of_numeric_int (pd_test_5_all.cpp:97549)
97539    // Nullable string EA — preserve.
97540    if (src == "string" || src.rfind("string[", 0) == 0)
97541        return std::string(src);
97542
97543    // Fallback.
97544    return "object";
97545}
97546
97547static std::vector<FillSpec> all_fills() {
97548    std::vector<FillSpec> v;
97549    v.push_back({"pi_0",    pandas::FillValue::of_numeric_int(0.0)});
97550    v.push_back({"pi_1",    pandas::FillValue::of_numeric_int(1.0)});
97551    v.push_back({"pi_neg5", pandas::FillValue::of_numeric_int(-5.0)});
97552    v.push_back({"pi_42",   pandas::FillValue::of_numeric_int(42.0)});
97553    v.push_back({"pf_0p0",  pandas::FillValue::of_numeric(0.0)});
97554    v.push_back({"pf_1p0",  pandas::FillValue::of_numeric(1.0)});
97555    v.push_back({"pf_neg5p0", pandas::FillValue::of_numeric(-5.0)});
97556    v.push_back({"pf_0p5",  pandas::FillValue::of_numeric(0.5)});
97557    v.push_back({"pf_1p5",  pandas::FillValue::of_numeric(1.5)});
97558    v.push_back({"pf_nan",  pandas::FillValue::of_numeric(std::numeric_limits<double>::quiet_NaN())});
97559    v.push_back({"pf_pinf", pandas::FillValue::of_numeric(std::numeric_limits<double>::infinity())});
of_string (pd_test_5_all.cpp:93146)
93136        local_fail);
93137    char k = pandas::cell_to_dtype_kind(r);
93138    pandas_tests::check(k == 'b',
93139        "C_26_apply_cell_result_case_3_of_bool()_dtype_kind",
93140        local_fail);
93141    if (k != 'b') std::cout << "  got=[" << k << "] expected=[b]\n";
93142}
93143
93144void case_4_of_string(int& local_fail) {
93145    std::cout << "-- case_4_of_string\n";
93146    pandas::ApplyCellResult r = pandas::ApplyCellResult::of_string(
93147        std::string("hello"));
93148    pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::String,
93149        "C_26_apply_cell_result_case_4_of_string()_kind",
93150        local_fail);
93151    pandas_tests::check(r.s == "hello",
93152        "C_26_apply_cell_result_case_4_of_string()_payload",
93153        local_fail);
93154    char k = pandas::cell_to_dtype_kind(r);
93155    pandas_tests::check(k == 'O',
93156        "C_26_apply_cell_result_case_4_of_string()_dtype_kind",
of_timedelta_ns (pd_test_5_all.cpp:93186)
93176        "C_26_apply_cell_result_case_5_of_timestamp_ns()_dtype_kind",
93177        local_fail);
93178    if (k != 'M') std::cout << "  got=[" << k << "] expected=[M]\n";
93179}
93180
93181void case_6_of_timedelta_ns(int& local_fail) {
93182    std::cout << "-- case_6_of_timedelta_ns\n";
93183    const int64_t ns = static_cast<int64_t>(86400) *
93184                       static_cast<int64_t>(1000000000);  // 1 day
93185    pandas::ApplyCellResult r =
93186        pandas::ApplyCellResult::of_timedelta_ns(ns);
93187    pandas_tests::check(
93188        r.kind == pandas::ApplyCellResult::Kind::Timedelta_ns,
93189        "C_26_apply_cell_result_case_6_of_timedelta_ns()_kind",
93190        local_fail);
93191    pandas_tests::check(r.td_ns == ns,
93192        "C_26_apply_cell_result_case_6_of_timedelta_ns()_payload",
93193        local_fail);
93194    char k = pandas::cell_to_dtype_kind(r);
93195    pandas_tests::check(k == 'm',
93196        "C_26_apply_cell_result_case_6_of_timedelta_ns()_dtype_kind",
of_timestamp_ns (pd_test_5_all.cpp:93166)
93156        "C_26_apply_cell_result_case_4_of_string()_dtype_kind",
93157        local_fail);
93158    if (k != 'O') std::cout << "  got=[" << k << "] expected=[O]\n";
93159}
93160
93161void case_5_of_timestamp_ns(int& local_fail) {
93162    std::cout << "-- case_5_of_timestamp_ns\n";
93163    const int64_t ns = static_cast<int64_t>(1700000000) *
93164                       static_cast<int64_t>(1000000000);
93165    pandas::ApplyCellResult r =
93166        pandas::ApplyCellResult::of_timestamp_ns(ns);
93167    pandas_tests::check(
93168        r.kind == pandas::ApplyCellResult::Kind::Timestamp_ns,
93169        "C_26_apply_cell_result_case_5_of_timestamp_ns()_kind",
93170        local_fail);
93171    pandas_tests::check(r.ts_ns == ns,
93172        "C_26_apply_cell_result_case_5_of_timestamp_ns()_payload",
93173        local_fail);
93174    char k = pandas::cell_to_dtype_kind(r);
93175    pandas_tests::check(k == 'M',
93176        "C_26_apply_cell_result_case_5_of_timestamp_ns()_dtype_kind",