FloatingDtype ============= .. cpp:class:: pandas::FloatingDtype Data type class for pandas extension types. Example ------- .. code-block:: cpp #include using namespace pandas; // Use FloatingDtype FloatingDtype obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``FloatingDtype() = default`` - pd_floating_dtype.h:31 - Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T max_value() const`` - T - pd_floating_dtype.h:82 - * - ``T min_value() const`` - T - pd_floating_dtype.h:75 - Iteration --------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``size_t itemsize() const override`` - size_t - pd_floating_dtype.h:53 - Type Checking ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static bool is_finite(T value)`` - static bool - pd_floating_dtype.h:96 - * - ``static bool is_inf(T value)`` - static bool - pd_floating_dtype.h:110 - * - ``static bool is_nan(T value)`` - static bool - pd_floating_dtype.h:103 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``T epsilon() const`` - T - pd_floating_dtype.h:89 - :ref:`View ` * - ``std::string kind() const override`` - std::string - pd_floating_dtype.h:61 - :ref:`View ` * - ``bool matches(const std::string& dtype_name) const`` - bool - pd_floating_dtype.h:119 - :ref:`View ` * - ``std::string name() const override`` - std::string - pd_floating_dtype.h:38 - :ref:`View ` * - ``numpy::DType numpy_dtype() const override`` - numpy::DType - pd_floating_dtype.h:46 - * - ``const std::type_info& type() const override`` - const std::type_info& - pd_floating_dtype.h:68 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-floatingdtype-is_nan-0: .. dropdown:: is_nan (pd_test_5_all.cpp:90959) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 90949 :emphasize-lines: 11 pandas::SetItemResult expected_kind, int& local_fail) { pandas_tests::check( got.aligned_values.size() == expected_size, label + ".aligned_values_size", local_fail); pandas_tests::check( got.kind == expected_kind, label + ".kind", local_fail); } static bool is_nan(double v) { return v != v; } void case_1_positional_int64() { int local_fail = 0; auto df = make_abc_frame(); auto s = make_labelled_series( {10, 20, 30}, {"a", "b", "c"}); auto r = pandas::align_series_to_dataframe( s, df.index(), /*preserve_dtype=*/true); .. _example-floatingdtype-epsilon-1: .. dropdown:: epsilon (pd_test_5_all.cpp:107634) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 107624 :emphasize-lines: 11 // Block I (Family 3/4 breadth): denormals + extremes. if (label == "float64_denorm_min") { const double tiny = std::numeric_limits::min(); return {tiny / 2.0, tiny / 4.0, 0.0}; } if (label == "float64_smallest_normal") { const double tiny = std::numeric_limits::min(); return {tiny, -tiny, 0.0}; } if (label == "float64_dbl_eps") { const double eps = std::numeric_limits::epsilon(); return {eps, -eps, 1.0}; } if (label == "float64_lowest") { return {std::numeric_limits::lowest(), 0.0, std::numeric_limits::max()}; } if (label == "float64_1e_minus_300") return {1e-300, -1e-300, 0.0}; if (label == "float64_1e_plus_300") return {1e300, -1e300, 1.5e300}; throw std::runtime_error("unknown float64 label: " + label); } .. _example-floatingdtype-kind-2: .. dropdown:: kind (pd_test_1_all.cpp:300) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 290 :emphasize-lines: 11 void pd_test_boolean_array_dtype() { std::cout << "========= BooleanArray: dtype ======================= "; pandas::BooleanArray arr; if (arr.dtype().name() != "boolean") { std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype name should be 'boolean'" << std::endl; throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype name"); } if (arr.dtype().kind() != "b") { std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype kind should be 'b'" << std::endl; throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype kind"); } std::cout << " -> tests passed" << std::endl; } } int pd_test_boolean_array_main() { std::cout << "====================================== running pd_test_boolean_array ==================================== " << std::endl; .. _example-floatingdtype-matches-3: .. dropdown:: matches (pd_test_5_all.cpp:15741) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15731 :emphasize-lines: 11 for (size_t i = 0; i < 5; ++i) { // DatetimeIndex serializes individual entries via get_value_str() bdate_first5.push_back(idx.get_value_str(i)); } std::cout << " case_4 bdate_range first 5: "; for (auto& s : bdate_first5) std::cout << s << " "; std::cout << "\n case_4 expected first 5: "; for (auto& s : expected_visible_head) std::cout << s << " "; std::cout << "\n"; // First date matches (both start at 2023-01-04) pandas_tests::check(contains(bdate_first5[0], "2023-01-04"), "case_4.first_bdate_is_2023-01-04", local_fail); // Second date should differ: bdate gives 2023-01-05, fixture wants 2023-01-20 bool second_matches_expected = contains(bdate_first5[1], "2023-01-20"); pandas_tests::check(!second_matches_expected, "case_4.bdate_NOT_matching_filtered_fixture", local_fail); // The bdate second is the next business day: pandas_tests::check(contains(bdate_first5[1], "2023-01-05"), "case_4.bdate_second_is_2023-01-05_sequential", local_fail); .. _example-floatingdtype-name-4: .. dropdown:: name (pd_test_1_all.cpp:295) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 285 :emphasize-lines: 11 throw std::runtime_error("pd_test_boolean_array_reductions failed: mean"); } std::cout << " -> tests passed" << std::endl; } void pd_test_boolean_array_dtype() { std::cout << "========= BooleanArray: dtype ======================= "; pandas::BooleanArray arr; if (arr.dtype().name() != "boolean") { std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype name should be 'boolean'" << std::endl; throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype name"); } if (arr.dtype().kind() != "b") { std::cout << " [FAIL] : in pd_test_boolean_array_dtype() : dtype kind should be 'b'" << std::endl; throw std::runtime_error("pd_test_boolean_array_dtype failed: dtype kind"); } std::cout << " -> tests passed" << std::endl; .. _example-floatingdtype-type-5: .. dropdown:: type (pd_test_3_all.cpp:15450) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 15440 :emphasize-lines: 11 /** * Test Series.convert_dtypes() parameter flags */ void pd_test_series_convert_dtypes_flags() { std::cout << "========= Series.convert_dtypes() flags ================="; // Test convert_integer=false - with floats disabled too, so it becomes string/object pandas::Series s({"1", "2", "3"}, "numbers"); auto converted = s.convert_dtypes(true, true, false, true, false); // convert_integer=false, convert_floating=false // Should remain object type (Series has dtype_name()="object") // When integer and floating are both disabled for integer-like strings, it falls back to string type if (converted->dtype_name() != "object") { std::cout << " [FAIL] : dtype should be object when convert_integer=false and convert_floating=false, got " << converted->dtype_name() << std::endl; throw std::runtime_error("pd_test_series_convert_dtypes_flags failed: convert_integer"); } // Test convert_boolean=false - strings stay as object/string type pandas::Series s_bool({"true", "false"}, "bools"); auto converted_bool = s_bool.convert_dtypes(true, true, true, false, true); // convert_boolean=false