PyTimedelta =========== .. cpp:class:: numpy::PyTimedelta numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use PyTimedelta PyTimedelta obj; // ... operations ... I/O --- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``std::string to_string() const`` - std::string - df_timedelta_array.h:88 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``double total_seconds() const`` - double - df_timedelta_array.h:79 - :ref:`View ` Code Examples ------------- The following examples are extracted from the test suite. .. _example-pytimedelta-to_string-0: .. dropdown:: to_string (np_test_1_all.cpp:454) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 444 :emphasize-lines: 11 // Modify through different views view1.setElementAt({0, 0}, 100); view2.setElementAt({2, 1}, 200); // This is (1, 2) in original view3.setElementAt({0, 0}, 300); // This is (1, 1) in original // std::cout << "After modifications through multiple views:" << std::endl; //original.printArray(); // Verify all changes are reflected if (!(original.getElementAt({0, 0}) == 100)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 2}) == 200)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } if (!(original.getElementAt({1, 1}) == 300)) { std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)"; .. _example-pytimedelta-total_seconds-1: .. dropdown:: total_seconds (np_test_5_all.cpp:21288) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 21278 :emphasize-lines: 11 } } // max() { numpy::Timedelta max_td = numpy::Timedelta::max(); if (max_td.value() != INT64_MAX) { std::cout << "[FAIL] np_test_timedelta_static_factories: max() expected INT64_MAX" << std::endl; errors++; } } // resolution() { numpy::Timedelta res = numpy::Timedelta::resolution(); if (res.value() != 1) { std::cout << "[FAIL] np_test_timedelta_static_factories: resolution() expected 1 ns" << std::endl; errors++; }