ApplyCellResult#
-
class pandas::ApplyCellResult#
pandas C++ class.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use ApplyCellResult
ApplyCellResult obj;
// ... operations ...
Constructors#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static ApplyCellResult |
pd_apply_result.h:115 |
|
|
static ApplyCellResult |
pd_apply_result.h:127 |
|
|
static ApplyCellResult |
pd_apply_result.h:102 |
|
|
static ApplyCellResult |
pd_apply_result.h:105 |
|
|
static ApplyCellResult |
pd_apply_result.h:136 |
|
|
static ApplyCellResult |
pd_apply_result.h:130 |
|
|
static ApplyCellResult |
pd_apply_result.h:133 |
|
|
static ApplyCellResult |
pd_apply_result.h:118 |
|
|
static ApplyCellResult |
pd_apply_result.h:124 |
|
|
static ApplyCellResult |
pd_apply_result.h:121 |
|
|
static ApplyCellResult |
pd_apply_result.h:112 |
Code Examples#
The following examples are extracted from the test suite.
ApplyCellResult (pd_test_5_all.cpp:94612)
94602 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::float32>>>) {
94603 return v ? v->dtype_name() : std::string("<null>");
94604 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::bool_>>>) {
94605 return v ? v->dtype_name() : std::string("<null>");
94606 } else {
94607 return "<other>";
94608 }
94609 }, r.value);
94610}
94611
94612static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
94613make_int_callable(int64_t v) {
94614 return [v](const pandas::Series<numpy::float64>&) {
94615 pandas::ApplyCellResult r;
94616 r.kind = pandas::ApplyCellResult::Int;
94617 r.i = v;
94618 return r;
94619 };
94620}
94621
94622static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
ApplyCellResult (pd_test_5_all.cpp:94612)
94602 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::float32>>>) {
94603 return v ? v->dtype_name() : std::string("<null>");
94604 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::bool_>>>) {
94605 return v ? v->dtype_name() : std::string("<null>");
94606 } else {
94607 return "<other>";
94608 }
94609 }, r.value);
94610}
94611
94612static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
94613make_int_callable(int64_t v) {
94614 return [v](const pandas::Series<numpy::float64>&) {
94615 pandas::ApplyCellResult r;
94616 r.kind = pandas::ApplyCellResult::Int;
94617 r.i = v;
94618 return r;
94619 };
94620}
94621
94622static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
ApplyCellResult (pd_test_5_all.cpp:94612)
94602 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::float32>>>) {
94603 return v ? v->dtype_name() : std::string("<null>");
94604 } else if constexpr (std::is_same_v<T, std::unique_ptr<pandas::Series<numpy::bool_>>>) {
94605 return v ? v->dtype_name() : std::string("<null>");
94606 } else {
94607 return "<other>";
94608 }
94609 }, r.value);
94610}
94611
94612static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
94613make_int_callable(int64_t v) {
94614 return [v](const pandas::Series<numpy::float64>&) {
94615 pandas::ApplyCellResult r;
94616 r.kind = pandas::ApplyCellResult::Int;
94617 r.i = v;
94618 return r;
94619 };
94620}
94621
94622static std::function<pandas::ApplyCellResult(const pandas::Series<numpy::float64>&)>
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_complex128 (pd_test_5_all.cpp:93204)
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",
93197 local_fail);
93198 if (k != 'm') std::cout << " got=[" << k << "] expected=[m]\n";
93199}
93200
93201void case_7_of_complex128(int& local_fail) {
93202 std::cout << "-- case_7_of_complex128\n";
93203 std::complex<double> z(1.5, -2.5);
93204 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_complex128(z);
93205 pandas_tests::check(
93206 r.kind == pandas::ApplyCellResult::Kind::Complex128,
93207 "C_26_apply_cell_result_case_7_of_complex128()_kind",
93208 local_fail);
93209 pandas_tests::check(r.c128.real() == 1.5 && r.c128.imag() == -2.5,
93210 "C_26_apply_cell_result_case_7_of_complex128()_payload",
93211 local_fail);
93212 char k = pandas::cell_to_dtype_kind(r);
93213 pandas_tests::check(k == 'c',
93214 "C_26_apply_cell_result_case_7_of_complex128()_dtype_kind",
of_float (pd_test_5_all.cpp:93097)
93087 }
93088 std::cout << " -> tests passed" << std::endl;
93089}
93090
93091// --- f_test_C_26_apply_cell_result_9.cpp ---
93092
93093namespace f_test_C_26_apply_cell_result_9_ns {
93094
93095void case_1_of_float(int& local_fail) {
93096 std::cout << "-- case_1_of_float\n";
93097 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_float(3.14);
93098 pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::Float,
93099 "C_26_apply_cell_result_case_1_of_float()_kind",
93100 local_fail);
93101 pandas_tests::check(r.flt == 3.14,
93102 "C_26_apply_cell_result_case_1_of_float()_payload",
93103 local_fail);
93104 char k = pandas::cell_to_dtype_kind(r);
93105 pandas_tests::check(k == 'f',
93106 "C_26_apply_cell_result_case_1_of_float()_dtype_kind",
93107 local_fail);
of_int (pd_test_5_all.cpp:93113)
93103 local_fail);
93104 char k = pandas::cell_to_dtype_kind(r);
93105 pandas_tests::check(k == 'f',
93106 "C_26_apply_cell_result_case_1_of_float()_dtype_kind",
93107 local_fail);
93108 if (k != 'f') std::cout << " got=[" << k << "] expected=[f]\n";
93109}
93110
93111void case_2_of_int(int& local_fail) {
93112 std::cout << "-- case_2_of_int\n";
93113 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_int(
93114 static_cast<int64_t>(42));
93115 pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::Int,
93116 "C_26_apply_cell_result_case_2_of_int()_kind",
93117 local_fail);
93118 pandas_tests::check(r.i64 == 42,
93119 "C_26_apply_cell_result_case_2_of_int()_payload",
93120 local_fail);
93121 char k = pandas::cell_to_dtype_kind(r);
93122 pandas_tests::check(k == 'i',
93123 "C_26_apply_cell_result_case_2_of_int()_dtype_kind",
of_monostate (pd_test_5_all.cpp:93261)
93251 local_fail);
93252 char k = pandas::cell_to_dtype_kind(r);
93253 pandas_tests::check(k == 'O',
93254 "C_26_apply_cell_result_case_9_of_series_string()_dtype_kind",
93255 local_fail);
93256 if (k != 'O') std::cout << " got=[" << k << "] expected=[O]\n";
93257}
93258
93259void case_10_of_monostate(int& local_fail) {
93260 std::cout << "-- case_10_of_monostate\n";
93261 pandas::ApplyCellResult r = pandas::ApplyCellResult::of_monostate();
93262 pandas_tests::check(
93263 r.kind == pandas::ApplyCellResult::Kind::Monostate,
93264 "C_26_apply_cell_result_case_10_of_monostate()_kind",
93265 local_fail);
93266 char k = pandas::cell_to_dtype_kind(r);
93267 pandas_tests::check(k == '?',
93268 "C_26_apply_cell_result_case_10_of_monostate()_dtype_kind",
93269 local_fail);
93270 if (k != '?') std::cout << " got=[" << k << "] expected=[?]\n";
93271}
of_series_float (pd_test_5_all.cpp:93224)
93214 "C_26_apply_cell_result_case_7_of_complex128()_dtype_kind",
93215 local_fail);
93216 if (k != 'c') std::cout << " got=[" << k << "] expected=[c]\n";
93217}
93218
93219void case_8_of_series_float(int& local_fail) {
93220 std::cout << "-- case_8_of_series_float\n";
93221 std::vector<numpy::float64> values{1.0, 2.0, 3.0};
93222 auto sp = std::make_unique<pandas::Series<numpy::float64>>(values);
93223 pandas::ApplyCellResult r =
93224 pandas::ApplyCellResult::of_series_float(std::move(sp));
93225 pandas_tests::check(
93226 r.kind == pandas::ApplyCellResult::Kind::SeriesFloat,
93227 "C_26_apply_cell_result_case_8_of_series_float()_kind",
93228 local_fail);
93229 pandas_tests::check(r.sf != nullptr,
93230 "C_26_apply_cell_result_case_8_of_series_float()_payload_nonnull",
93231 local_fail);
93232 char k = pandas::cell_to_dtype_kind(r);
93233 pandas_tests::check(k == 'O',
93234 "C_26_apply_cell_result_case_8_of_series_float()_dtype_kind",
of_series_string (pd_test_5_all.cpp:93244)
93234 "C_26_apply_cell_result_case_8_of_series_float()_dtype_kind",
93235 local_fail);
93236 if (k != 'O') std::cout << " got=[" << k << "] expected=[O]\n";
93237}
93238
93239void case_9_of_series_string(int& local_fail) {
93240 std::cout << "-- case_9_of_series_string\n";
93241 std::vector<std::string> values{"a", "b", "c"};
93242 auto sp = std::make_unique<pandas::Series<std::string>>(values);
93243 pandas::ApplyCellResult r =
93244 pandas::ApplyCellResult::of_series_string(std::move(sp));
93245 pandas_tests::check(
93246 r.kind == pandas::ApplyCellResult::Kind::SeriesString,
93247 "C_26_apply_cell_result_case_9_of_series_string()_kind",
93248 local_fail);
93249 pandas_tests::check(r.ss != nullptr,
93250 "C_26_apply_cell_result_case_9_of_series_string()_payload_nonnull",
93251 local_fail);
93252 char k = pandas::cell_to_dtype_kind(r);
93253 pandas_tests::check(k == 'O',
93254 "C_26_apply_cell_result_case_9_of_series_string()_dtype_kind",
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",
of_uint64 (pd_test_5_all.cpp:128111)
128101 std::string note;
128102};
128103
128104using CaseFn = void(*)(int&, const ExpectedRow&);
128105
128106template <typename T>
128107static pandas::ApplyCellResult typed_axis0_sum_cell(const pandas::Series<numpy::float64>& c) {
128108 double s = 0.0;
128109 for (size_t i = 0; i < static_cast<size_t>(c.size()); ++i) s += c.get_value_double(i);
128110 if constexpr (std::is_unsigned_v<T> && !std::is_same_v<T, bool>) {
128111 return pandas::ApplyCellResult::of_uint64(static_cast<uint64_t>(s));
128112 } else if constexpr (std::is_floating_point_v<T>) {
128113 return pandas::ApplyCellResult::of_float(s);
128114 } else {
128115 return pandas::ApplyCellResult::of_int(static_cast<int64_t>(s));
128116 }
128117}
128118
128119template <typename T>
128120static pandas::ApplyCellResult typed_axis1_sum_cell(const pandas::Series<numpy::float64>& r) {
128121 double s = 0.0;