FillSpec#
-
class pandas::FillSpec#
pandas C++ class.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use FillSpec
FillSpec obj;
// ... operations ...
Construction#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static FillSpec |
pd_dataframe.h:203 |
Conversion#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static FillSpec |
pd_dataframe.h:197 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static FillSpec |
pd_dataframe.h:199 |
|
|
static FillSpec |
pd_dataframe.h:198 |
|
|
static FillSpec |
pd_dataframe.h:196 |
|
|
static FillSpec |
pd_dataframe.h:200 |
Code Examples#
The following examples are extracted from the test suite.
boolean (pd_test_2_all.cpp:20240)
20230void pd_test_getitem_dispatch_classify_bool() {
20231 std::cout << "pd_test_getitem_dispatch_classify_bool" << std::endl;
20232 pandas::DataFrame df;
20233 std::vector<numpy::bool_> bvals = {true, false, true};
20234 df.insert(0, "flag", std::make_unique<pandas::Series<numpy::bool_>>(bvals, "flag"), true);
20235
20236 auto t = df.classify_column_access("flag");
20237 check(t == pandas::DataFrame::ColumnAccessType::BoolColumn, "bool -> BoolColumn");
20238
20239 // boolean (nullable) dtype
20240 pandas::DataFrame df2;
20241 auto bs = std::make_unique<pandas::Series<numpy::bool_>>(bvals, "flag2");
20242 bs->set_dtype_override("boolean");
20243 df2.insert(0, "flag2", std::move(bs), true);
20244 auto t2 = df2.classify_column_access("flag2");
20245 check(t2 == pandas::DataFrame::ColumnAccessType::BoolColumn, "boolean -> BoolColumn");
20246}
20247
20248void pd_test_getitem_dispatch_classify_string() {
20249 std::cout << "pd_test_getitem_dispatch_classify_string" << std::endl;
floating (pd_test_5_all.cpp:90472)
90462static void f_20_847316_df_reindex_with_spec_dup(int& local_fail) {
90463 std::cout << "-- f_20_847316_df_reindex_with_spec_dup\n";
90464 expect_value_error_duplicate("c16_df_reindex_with_spec", [] {
90465 std::vector<pandas::Series<std::int64_t>> cols;
90466 cols.emplace_back(std::vector<std::int64_t>{10, 20, 30});
90467 cols.emplace_back(std::vector<std::int64_t>{40, 50, 60});
90468 pandas::DataFrame df(cols, {"c1", "c2"});
90469 df.set_index(std::make_unique<pandas::Index<std::string>>(
90470 std::vector<std::string>{"a", "a", "b"}));
90471 pandas::FillSpec spec = pandas::FillSpec::floating(0.0);
90472 auto r = df.reindex_with_spec({"a", "b", "c"}, /*axis=*/0, spec);
90473 (void)r;
90474 }, local_fail);
90475}
90476
90477static void f_20_847317_series_unique_succeeds(int& local_fail) {
90478 std::cout << "-- f_20_847317_series_unique_succeeds\n";
90479 expect_no_exception("c17_series_unique", [&local_fail] {
90480 auto s = make_series<std::int64_t>({1, 2, 3}, {"a", "b", "c"});
90481 auto r = s.reindex({"a", "b", "c", "d"});
integer (pd_test_1_all.cpp:2897)
2887 void pd_test_period_array_arithmetic() {
2888 std::cout << "========= PeriodArray: arithmetic ======================= ";
2889
2890 pandas::PeriodArray arr(std::vector<std::string>{
2891 "2024-01",
2892 "2024-06",
2893 "NaT"
2894 }, "M");
2895
2896 // Add integer (shift forward)
2897 auto shifted = arr + 3;
2898 if (shifted.size() != 3) {
2899 std::cout << " [FAIL] : shifted size should be 3" << std::endl;
2900 throw std::runtime_error("pd_test_period_array_arithmetic failed: size");
2901 }
2902
2903 // Check ordinal shifted by 3
2904 auto orig0 = arr[0];
2905 auto shift0 = shifted[0];
2906 if (!orig0.has_value() || !shift0.has_value() ||
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;
string (pd_test_1_all.cpp:941)
931#include "../pandas/pd_config.h"
932
933namespace dataframe_tests {
934
935namespace dataframe_tests_config {
936
937 void pd_test_config_version() {
938 std::cout << "========= df_config: version info ======================= ";
939 const char* version = pandas::DataFrameInfo::version();
940 if (version == nullptr || std::string(version).empty()) {
941 std::cout << "[FAIL] : in pd_test_config_version() : version is null or empty" << std::endl;
942 throw std::runtime_error("pd_test_config_version failed: version is null or empty");
943 }
944 std::cout << "-> tests passed" << std::endl;
945 }
946
947 void pd_test_config_na_repr() {
948 std::cout << "========= df_config: NA representation ======================= ";
949 const char* na_repr = pandas::DataFrameConfig::get_na_repr();
950 if (na_repr == nullptr) {