PandasOptions ============= .. cpp:class:: pandas::PandasOptions Utility class for pandas operations. Example ------- .. code-block:: cpp #include using namespace pandas; // Use PandasOptions PandasOptions obj; // ... operations ... Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T get(const std::string& key) const`` - T - pd_top_level.h:203 - :ref:`View ` Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string describe(const std::string& pattern = "") const`` - std::string - pd_top_level.h:240 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static PandasOptions& instance()`` - static PandasOptions& - pd_top_level.h:197 - * - ``std::vector list_options() const`` - std::vector - pd_top_level.h:281 - * - ``void reset(const std::string& key)`` - void - pd_top_level.h:228 - :ref:`View ` * - ``void reset_all()`` - void - pd_top_level.h:236 - * - ``void set(const std::string& key, const T& value)`` - void - pd_top_level.h:216 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-pandasoptions-get-0: .. dropdown:: get (pd_test_1_all.cpp:10290) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 10280 :emphasize-lines: 11 void pd_test_extension_index_get_loc_unique() { std::cout << "========= get_loc (unique) ========================="; pandas::CategoricalArray arr({"apple", "banana", "cherry"}); pandas::CategoricalIndex idx(arr); auto loc_apple = idx.get_loc("apple"); auto loc_banana = idx.get_loc("banana"); auto loc_cherry = idx.get_loc("cherry"); bool passed = (std::holds_alternative(loc_apple) && std::get(loc_apple) == 0 && std::get(loc_banana) == 1 && std::get(loc_cherry) == 2); if (!passed) { std::cout << " [FAIL] : in pd_test_extension_index_get_loc_unique() : get_loc check failed" << std::endl; throw std::runtime_error("pd_test_extension_index_get_loc_unique failed"); } std::cout << " -> tests passed" << std::endl; } .. _example-pandasoptions-describe-1: .. dropdown:: describe (pd_test_2_all.cpp:19793) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 19783 :emphasize-lines: 11 ++g_fail; } } static bool approx_eq(double a, double b, double tol = 1e-9) { if (std::isnan(a) && std::isnan(b)) return true; return std::abs(a - b) < tol; } // ===================================================================== // Test: describe() default mode — numeric columns only // ===================================================================== void pd_test_describe_numeric_only() { std::cout << " -- pd_test_describe_numeric_only --" << std::endl; pandas::DataFrame df; df.add_column("A", std::vector{1.0, 2.0, 3.0, 4.0, 5.0}); df.add_column("B", std::vector{10.0, 20.0, 30.0, 40.0, 50.0}); df.add_column("Name", std::vector{"a", "b", "c", "d", "e"}); .. _example-pandasoptions-reset-2: .. dropdown:: reset (pd_test_1_all.cpp:16254) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16244 :emphasize-lines: 11 // Test copy pandas::Flags f4 = f2; passed = f4 == f2; if (!passed) { std::cout << " [FAIL] : in pd_test_ndframe_flags() : copy constructor" << std::endl; throw std::runtime_error("pd_test_ndframe_flags failed: copy constructor"); } // Test reset f4.reset(); passed = f4.allows_duplicate_labels == true && f4.copy_on_write == false; if (!passed) { std::cout << " [FAIL] : in pd_test_ndframe_flags() : reset()" << std::endl; throw std::runtime_error("pd_test_ndframe_flags failed: reset()"); } std::cout << " -> tests passed" << std::endl; } // ===================================================================== .. _example-pandasoptions-set-3: .. dropdown:: set (pd_test_1_all.cpp:16281) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 16271 :emphasize-lines: 11 pandas::Attrs attrs; // Test empty bool passed = attrs.empty() && attrs.size() == 0; if (!passed) { std::cout << " [FAIL] : in pd_test_ndframe_attrs() : empty attrs" << std::endl; throw std::runtime_error("pd_test_ndframe_attrs failed: empty attrs"); } // Test set/get string attrs.set("author", std::string("John Doe")); passed = attrs.contains("author") && attrs.get("author") == "John Doe"; if (!passed) { std::cout << " [FAIL] : in pd_test_ndframe_attrs() : set/get string" << std::endl; throw std::runtime_error("pd_test_ndframe_attrs failed: set/get string"); } // Test set/get double attrs.set("version", 1.5); passed = std::abs(attrs.get("version") - 1.5) < 1e-10; if (!passed) {