PyTimedelta#
-
class pandas::PyTimedelta#
Scalar type representing a single value.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use PyTimedelta
PyTimedelta obj;
// ... operations ...
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
pd_timedelta_array.h:90 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
double |
pd_timedelta_array.h:81 |
Code Examples#
The following examples are extracted from the test suite.
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
total_seconds (pd_test_1_all.cpp:4224)
4214 void pd_test_timedelta_array_total_seconds() {
4215 std::cout << "========= TimedeltaArray: total_seconds ======================= ";
4216
4217 pandas::TimedeltaArray arr({
4218 std::optional<numpy::timedelta64>(numpy::timedelta64(1, numpy::DateTimeUnit::Day)),
4219 std::optional<numpy::timedelta64>(numpy::timedelta64(1, numpy::DateTimeUnit::Hour)),
4220 std::nullopt
4221 });
4222
4223 auto total = arr.total_seconds();
4224
4225 auto t0 = total[0];
4226 if (!t0.has_value() || std::abs(t0.value() - 86400.0) > 0.001) {
4227 std::cout << " [FAIL] : total_seconds[0] should be 86400" << std::endl;
4228 throw std::runtime_error("pd_test_timedelta_array_total_seconds failed: total_seconds[0]");
4229 }
4230
4231 auto t1 = total[1];
4232 if (!t1.has_value() || std::abs(t1.value() - 3600.0) > 0.001) {
4233 std::cout << " [FAIL] : total_seconds[1] should be 3600" << std::endl;