ApplyCellResult =============== .. cpp:class:: pandas::ApplyCellResult pandas C++ class. Example ------- .. code-block:: cpp #include using namespace pandas; // Use ApplyCellResult ApplyCellResult obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``ApplyCellResult() = default`` - pd_apply_result.h:95 - :ref:`View ` * - ``ApplyCellResult(ApplyCellResult&&) noexcept = default`` - pd_apply_result.h:96 - :ref:`View ` * - ``ApplyCellResult(const ApplyCellResult&) = delete`` - pd_apply_result.h:98 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static ApplyCellResult of_bool(bool b)`` - static ApplyCellResult - pd_apply_result.h:115 - :ref:`View ` * - ``static ApplyCellResult of_complex128(std::complex c)`` - static ApplyCellResult - pd_apply_result.h:127 - :ref:`View ` * - ``static ApplyCellResult of_float(double x)`` - static ApplyCellResult - pd_apply_result.h:102 - :ref:`View ` * - ``static ApplyCellResult of_int(int64_t x)`` - static ApplyCellResult - pd_apply_result.h:105 - :ref:`View ` * - ``static ApplyCellResult of_monostate()`` - static ApplyCellResult - pd_apply_result.h:136 - :ref:`View ` * - ``static ApplyCellResult of_series_float(std::unique_ptr> p)`` - static ApplyCellResult - pd_apply_result.h:130 - :ref:`View ` * - ``static ApplyCellResult of_series_string(std::unique_ptr> p)`` - static ApplyCellResult - pd_apply_result.h:133 - :ref:`View ` * - ``static ApplyCellResult of_string(std::string s)`` - static ApplyCellResult - pd_apply_result.h:118 - :ref:`View ` * - ``static ApplyCellResult of_timedelta_ns(int64_t ns)`` - static ApplyCellResult - pd_apply_result.h:124 - :ref:`View ` * - ``static ApplyCellResult of_timestamp_ns(int64_t ns)`` - static ApplyCellResult - pd_apply_result.h:121 - :ref:`View ` * - ``static ApplyCellResult of_uint64(uint64_t x)`` - static ApplyCellResult - pd_apply_result.h:112 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-applycellresult-applycellresult-0: .. dropdown:: ApplyCellResult (pd_test_5_all.cpp:94612) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 94602 :emphasize-lines: 11 } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else { return ""; } }, r.value); } static std::function&)> make_int_callable(int64_t v) { return [v](const pandas::Series&) { pandas::ApplyCellResult r; r.kind = pandas::ApplyCellResult::Int; r.i = v; return r; }; } static std::function&)> .. _example-applycellresult-applycellresult-1: .. dropdown:: ApplyCellResult (pd_test_5_all.cpp:94612) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 94602 :emphasize-lines: 11 } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else { return ""; } }, r.value); } static std::function&)> make_int_callable(int64_t v) { return [v](const pandas::Series&) { pandas::ApplyCellResult r; r.kind = pandas::ApplyCellResult::Int; r.i = v; return r; }; } static std::function&)> .. _example-applycellresult-applycellresult-2: .. dropdown:: ApplyCellResult (pd_test_5_all.cpp:94612) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 94602 :emphasize-lines: 11 } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else if constexpr (std::is_same_v>>) { return v ? v->dtype_name() : std::string(""); } else { return ""; } }, r.value); } static std::function&)> make_int_callable(int64_t v) { return [v](const pandas::Series&) { pandas::ApplyCellResult r; r.kind = pandas::ApplyCellResult::Int; r.i = v; return r; }; } static std::function&)> .. _example-applycellresult-of_bool-3: .. dropdown:: of_bool (pd_test_5_all.cpp:90403) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 90393 :emphasize-lines: 11 pandas::FillValue::of_numeric(nan)); (void)r; }, local_fail); } static void f_20_847311_dispatch_int64_bool_fill(int& local_fail) { std::cout << "-- f_20_847311_dispatch_int64_bool_fill\n"; expect_value_error_duplicate("c11_dispatch_int64_bool", [] { auto s = make_series({1, 2, 3}, {"a", "a", "b"}); auto r = s.reindex_dispatch({"a", "b", "c"}, "", pandas::FillValue::of_bool(true)); (void)r; }, local_fail); } static void f_20_847312_dispatch_complex_none(int& local_fail) { std::cout << "-- f_20_847312_dispatch_complex_none\n"; expect_value_error_duplicate("c12_dispatch_complex_none", [] { auto s = make_series({{1, 2}, {3, 4}, {5, 6}}, {"c1", "c1", "c2"}); auto r = s.reindex_dispatch({"c1", "c2", "c3"}, "", pandas::FillValue::none()); .. _example-applycellresult-of_complex128-4: .. dropdown:: of_complex128 (pd_test_5_all.cpp:93204) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93194 :emphasize-lines: 11 char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'm', "C_26_apply_cell_result_case_6_of_timedelta_ns()_dtype_kind", local_fail); if (k != 'm') std::cout << " got=[" << k << "] expected=[m]\n"; } void case_7_of_complex128(int& local_fail) { std::cout << "-- case_7_of_complex128\n"; std::complex z(1.5, -2.5); pandas::ApplyCellResult r = pandas::ApplyCellResult::of_complex128(z); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::Complex128, "C_26_apply_cell_result_case_7_of_complex128()_kind", local_fail); pandas_tests::check(r.c128.real() == 1.5 && r.c128.imag() == -2.5, "C_26_apply_cell_result_case_7_of_complex128()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'c', "C_26_apply_cell_result_case_7_of_complex128()_dtype_kind", .. _example-applycellresult-of_float-5: .. dropdown:: of_float (pd_test_5_all.cpp:93097) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93087 :emphasize-lines: 11 } std::cout << " -> tests passed" << std::endl; } // --- f_test_C_26_apply_cell_result_9.cpp --- namespace f_test_C_26_apply_cell_result_9_ns { void case_1_of_float(int& local_fail) { std::cout << "-- case_1_of_float\n"; pandas::ApplyCellResult r = pandas::ApplyCellResult::of_float(3.14); pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::Float, "C_26_apply_cell_result_case_1_of_float()_kind", local_fail); pandas_tests::check(r.flt == 3.14, "C_26_apply_cell_result_case_1_of_float()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'f', "C_26_apply_cell_result_case_1_of_float()_dtype_kind", local_fail); .. _example-applycellresult-of_int-6: .. dropdown:: of_int (pd_test_5_all.cpp:93113) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93103 :emphasize-lines: 11 local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'f', "C_26_apply_cell_result_case_1_of_float()_dtype_kind", local_fail); if (k != 'f') std::cout << " got=[" << k << "] expected=[f]\n"; } void case_2_of_int(int& local_fail) { std::cout << "-- case_2_of_int\n"; pandas::ApplyCellResult r = pandas::ApplyCellResult::of_int( static_cast(42)); pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::Int, "C_26_apply_cell_result_case_2_of_int()_kind", local_fail); pandas_tests::check(r.i64 == 42, "C_26_apply_cell_result_case_2_of_int()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'i', "C_26_apply_cell_result_case_2_of_int()_dtype_kind", .. _example-applycellresult-of_monostate-7: .. dropdown:: of_monostate (pd_test_5_all.cpp:93261) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93251 :emphasize-lines: 11 local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'O', "C_26_apply_cell_result_case_9_of_series_string()_dtype_kind", local_fail); if (k != 'O') std::cout << " got=[" << k << "] expected=[O]\n"; } void case_10_of_monostate(int& local_fail) { std::cout << "-- case_10_of_monostate\n"; pandas::ApplyCellResult r = pandas::ApplyCellResult::of_monostate(); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::Monostate, "C_26_apply_cell_result_case_10_of_monostate()_kind", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == '?', "C_26_apply_cell_result_case_10_of_monostate()_dtype_kind", local_fail); if (k != '?') std::cout << " got=[" << k << "] expected=[?]\n"; } .. _example-applycellresult-of_series_float-8: .. dropdown:: of_series_float (pd_test_5_all.cpp:93224) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93214 :emphasize-lines: 11 "C_26_apply_cell_result_case_7_of_complex128()_dtype_kind", local_fail); if (k != 'c') std::cout << " got=[" << k << "] expected=[c]\n"; } void case_8_of_series_float(int& local_fail) { std::cout << "-- case_8_of_series_float\n"; std::vector values{1.0, 2.0, 3.0}; auto sp = std::make_unique>(values); pandas::ApplyCellResult r = pandas::ApplyCellResult::of_series_float(std::move(sp)); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::SeriesFloat, "C_26_apply_cell_result_case_8_of_series_float()_kind", local_fail); pandas_tests::check(r.sf != nullptr, "C_26_apply_cell_result_case_8_of_series_float()_payload_nonnull", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'O', "C_26_apply_cell_result_case_8_of_series_float()_dtype_kind", .. _example-applycellresult-of_series_string-9: .. dropdown:: of_series_string (pd_test_5_all.cpp:93244) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93234 :emphasize-lines: 11 "C_26_apply_cell_result_case_8_of_series_float()_dtype_kind", local_fail); if (k != 'O') std::cout << " got=[" << k << "] expected=[O]\n"; } void case_9_of_series_string(int& local_fail) { std::cout << "-- case_9_of_series_string\n"; std::vector values{"a", "b", "c"}; auto sp = std::make_unique>(values); pandas::ApplyCellResult r = pandas::ApplyCellResult::of_series_string(std::move(sp)); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::SeriesString, "C_26_apply_cell_result_case_9_of_series_string()_kind", local_fail); pandas_tests::check(r.ss != nullptr, "C_26_apply_cell_result_case_9_of_series_string()_payload_nonnull", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'O', "C_26_apply_cell_result_case_9_of_series_string()_dtype_kind", .. _example-applycellresult-of_string-10: .. dropdown:: of_string (pd_test_5_all.cpp:93146) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93136 :emphasize-lines: 11 local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'b', "C_26_apply_cell_result_case_3_of_bool()_dtype_kind", local_fail); if (k != 'b') std::cout << " got=[" << k << "] expected=[b]\n"; } void case_4_of_string(int& local_fail) { std::cout << "-- case_4_of_string\n"; pandas::ApplyCellResult r = pandas::ApplyCellResult::of_string( std::string("hello")); pandas_tests::check(r.kind == pandas::ApplyCellResult::Kind::String, "C_26_apply_cell_result_case_4_of_string()_kind", local_fail); pandas_tests::check(r.s == "hello", "C_26_apply_cell_result_case_4_of_string()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'O', "C_26_apply_cell_result_case_4_of_string()_dtype_kind", .. _example-applycellresult-of_timedelta_ns-11: .. dropdown:: of_timedelta_ns (pd_test_5_all.cpp:93186) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93176 :emphasize-lines: 11 "C_26_apply_cell_result_case_5_of_timestamp_ns()_dtype_kind", local_fail); if (k != 'M') std::cout << " got=[" << k << "] expected=[M]\n"; } void case_6_of_timedelta_ns(int& local_fail) { std::cout << "-- case_6_of_timedelta_ns\n"; const int64_t ns = static_cast(86400) * static_cast(1000000000); // 1 day pandas::ApplyCellResult r = pandas::ApplyCellResult::of_timedelta_ns(ns); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::Timedelta_ns, "C_26_apply_cell_result_case_6_of_timedelta_ns()_kind", local_fail); pandas_tests::check(r.td_ns == ns, "C_26_apply_cell_result_case_6_of_timedelta_ns()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'm', "C_26_apply_cell_result_case_6_of_timedelta_ns()_dtype_kind", .. _example-applycellresult-of_timestamp_ns-12: .. dropdown:: of_timestamp_ns (pd_test_5_all.cpp:93166) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 93156 :emphasize-lines: 11 "C_26_apply_cell_result_case_4_of_string()_dtype_kind", local_fail); if (k != 'O') std::cout << " got=[" << k << "] expected=[O]\n"; } void case_5_of_timestamp_ns(int& local_fail) { std::cout << "-- case_5_of_timestamp_ns\n"; const int64_t ns = static_cast(1700000000) * static_cast(1000000000); pandas::ApplyCellResult r = pandas::ApplyCellResult::of_timestamp_ns(ns); pandas_tests::check( r.kind == pandas::ApplyCellResult::Kind::Timestamp_ns, "C_26_apply_cell_result_case_5_of_timestamp_ns()_kind", local_fail); pandas_tests::check(r.ts_ns == ns, "C_26_apply_cell_result_case_5_of_timestamp_ns()_payload", local_fail); char k = pandas::cell_to_dtype_kind(r); pandas_tests::check(k == 'M', "C_26_apply_cell_result_case_5_of_timestamp_ns()_dtype_kind", .. _example-applycellresult-of_uint64-13: .. dropdown:: of_uint64 (pd_test_5_all.cpp:128111) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 128101 :emphasize-lines: 11 std::string note; }; using CaseFn = void(*)(int&, const ExpectedRow&); template static pandas::ApplyCellResult typed_axis0_sum_cell(const pandas::Series& c) { double s = 0.0; for (size_t i = 0; i < static_cast(c.size()); ++i) s += c.get_value_double(i); if constexpr (std::is_unsigned_v && !std::is_same_v) { return pandas::ApplyCellResult::of_uint64(static_cast(s)); } else if constexpr (std::is_floating_point_v) { return pandas::ApplyCellResult::of_float(s); } else { return pandas::ApplyCellResult::of_int(static_cast(s)); } } template static pandas::ApplyCellResult typed_axis1_sum_cell(const pandas::Series& r) { double s = 0.0;