DatetimeTimedeltaMixin#
-
class numpy::DatetimeTimedeltaMixin#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use DatetimeTimedeltaMixin
DatetimeTimedeltaMixin obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_datetime_timedelta_mixin.h:104 |
|
|
df_datetime_timedelta_mixin.h:112 |
|
|
df_datetime_timedelta_mixin.h:120 |
|
|
df_datetime_timedelta_mixin.h:127 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static int64_t |
df_datetime_timedelta_mixin.h:612 |
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::optional<value_type> |
df_datetime_timedelta_mixin.h:389 |
Math Operations#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:319 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:300 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:281 |
|
|
static ArrayType |
df_datetime_timedelta_mixin.h:699 |
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
df_datetime_timedelta_mixin.h:525 |
Type Handling#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:507 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:219 |
|
|
std::unique_ptr<IndexBase> |
df_datetime_timedelta_mixin.h:498 |
|
|
static ArrayType |
df_datetime_timedelta_mixin.h:642 |
|
|
static int64_t |
df_datetime_timedelta_mixin.h:679 |
|
|
* pandas::DatetimeTDMixin |
df_datetime_timedelta_mixin.h:192 |
|
|
std::string |
df_datetime_timedelta_mixin.h:570 |
|
|
static numpy::DateTimeUnit |
df_datetime_timedelta_mixin.h:596 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:517 |
|
|
std::string |
df_datetime_timedelta_mixin.h:562 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:508 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:448 |
|
|
DatetimeTimedeltaMixin |
df_datetime_timedelta_mixin.h:334 |
|
|
std::string |
df_datetime_timedelta_mixin.h:196 |
Internal Methods#
2 internal methods (prefixed with underscore)
Code Examples#
The following examples are extracted from the test suite.
mean (np_test_1_all.cpp:11714)
11704 // Create test array
11705 auto array = createInt32Array({ 2, 3 }, 0);
11706 array.setElementAt({ 0, 0 }, 1);
11707 array.setElementAt({ 0, 1 }, 2);
11708 array.setElementAt({ 0, 2 }, 3);
11709 array.setElementAt({ 1, 0 }, 4);
11710 array.setElementAt({ 1, 1 }, 5);
11711 array.setElementAt({ 1, 2 }, 6);
11712
11713 // Test mean without axis
11714 auto mean_all = mean(array);
11715 if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717 std::cout << std::string("[FAIL] ") + description << std::endl;
11718 throw std::runtime_error(description);
11719 }
11720 // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722 // Test mean along axis 0
11723 auto mean_axis0 = mean(array, 0);
11724 if (!(mean_axis0.getShape()[0] == 3)) {
ceil (np_test_2_all.cpp:5735)
5725 throw std::runtime_error(description);
5726 }
5727 if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729 std::cout << std::string("[FAIL] ") + description << std::endl;
5730 throw std::runtime_error(description);
5731 }
5732 // std::cout << "[OK] floor function works correctly\n";
5733
5734 // Test ceil
5735 auto ceil_result = ceil(values);
5736 if (!(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))) {
5737 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 0 }), std::ceil(-2.7)))";
5738 std::cout << std::string("[FAIL] ") + description << std::endl;
5739 throw std::runtime_error(description);
5740 }
5741 if (!(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))) {
5742 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(ceil_result.getElementAt({ 5 }), std::ceil(2.7)))";
5743 std::cout << std::string("[FAIL] ") + description << std::endl;
5744 throw std::runtime_error(description);
5745 }
floor (np_test_2_all.cpp:5721)
5711 throw std::runtime_error(description);
5712 }
5713 if (!(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))) {
5714 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(round_result.getElementAt({ 5 }), std::round(2.7)))";
5715 std::cout << std::string("[FAIL] ") + description << std::endl;
5716 throw std::runtime_error(description);
5717 }
5718 // std::cout << "[OK] round function works correctly\n";
5719
5720 // Test floor
5721 auto floor_result = floor(values);
5722 if (!(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))) {
5723 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 0 }), std::floor(-2.7)))";
5724 std::cout << std::string("[FAIL] ") + description << std::endl;
5725 throw std::runtime_error(description);
5726 }
5727 if (!(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))) {
5728 std::string description = std::string("testRoundingFunctions():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(floor_result.getElementAt({ 5 }), std::floor(2.7)))";
5729 std::cout << std::string("[FAIL] ") + description << std::endl;
5730 throw std::runtime_error(description);
5731 }
round (np_test_1_all.cpp:23769)
23759 throw std::runtime_error(description);
23760 }
23761 if (!(power_scalar_result.getShape() == array.getShape())) {
23762 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(power_scalar_result.getShape() == array.getShape())";
23763 std::cout << std::string("[FAIL] ") + description << std::endl;
23764 throw std::runtime_error(description);
23765 }
23766 // std::cout << "[OK] Power functions have correct signatures\n";
23767
23768 // Test rounding functions with new decimals parameter
23769 auto round_result = round(array); // Default decimals=0
23770 auto round_decimals_result = round(array, 2); // With decimals
23771 if (!(round_result.getShape() == array.getShape())) {
23772 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_result.getShape() == array.getShape())";
23773 std::cout << std::string("[FAIL] ") + description << std::endl;
23774 throw std::runtime_error(description);
23775 }
23776 if (!(round_decimals_result.getShape() == array.getShape())) {
23777 std::string description = std::string("testMathFunctionSignatures():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(round_decimals_result.getShape() == array.getShape())";
23778 std::cout << std::string("[FAIL] ") + description << std::endl;
23779 throw std::runtime_error(description);
to_string (np_test_1_all.cpp:454)
444 // Modify through different views
445 view1.setElementAt({0, 0}, 100);
446 view2.setElementAt({2, 1}, 200); // This is (1, 2) in original
447 view3.setElementAt({0, 0}, 300); // This is (1, 1) in original
448
449 // std::cout << "After modifications through multiple views:" << std::endl;
450 //original.printArray();
451
452 // Verify all changes are reflected
453 if (!(original.getElementAt({0, 0}) == 100)) {
454 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455 std::cout << std::string("[FAIL] ") + description << std::endl;
456 throw std::runtime_error(description);
457 }
458 if (!(original.getElementAt({1, 2}) == 200)) {
459 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460 std::cout << std::string("[FAIL] ") + description << std::endl;
461 throw std::runtime_error(description);
462 }
463 if (!(original.getElementAt({1, 1}) == 300)) {
464 std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";
copy (np_test_1_all.cpp:9812)
9802 //original.printArray();
9803
9804 // The modification should be at position (1,1) in original
9805 if (!(original.getElementAt({1, 1}) == 9999)) {
9806 std::string description = std::string("testSliceCopyVsViewMemoryOwnership():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 9999)";
9807 std::cout << std::string("[FAIL] ") + description << std::endl;
9808 throw std::runtime_error(description);
9809 }
9810 // std::cout << "[OK] Slice view shares memory with original";
9811
9812 // Test slice copy (should be independent)
9813 auto slice_copy = original.sliceArray({{2, 4}, {2, 4}});
9814 // std::cout << "Slice copy [2:4, 2:4]:";
9815 //slice_copy.printArray();
9816
9817 slice_copy.setElementAt({0, 0}, 7777);
9818
9819 // std::cout << "After modifying slice copy at (0,0):" << std::endl;
9820 // std::cout << "Original array:" << std::endl;
9821 //original.printArray();
9822 // std::cout << "Slice copy:" << std::endl;
as_unit (np_test_5_all.cpp:22866)
22856 if (iso_week < 1 || iso_week > 53) { pass = false; fail_msg = "ISO week range"; }
22857 if (iso_day < 1 || iso_day > 7) { pass = false; fail_msg = "ISO day range 1-7"; }
22858
22859 // isoweekday (1=Monday, 7=Sunday)
22860 int isowd = ts.isoweekday();
22861 if (isowd != 6) { pass = false; fail_msg = "2024-06-15 is Saturday = 6"; }
22862
22863 // weekday (0=Monday, 6=Sunday)
22864 int wd = ts.weekday();
22865 if (wd != 5) { pass = false; fail_msg = "2024-06-15 is Saturday = 5"; }
22866
22867 if (!pass) {
22868 std::cout << " [FAIL] : in np_test_timestamp_calendar() : " << fail_msg;
22869 throw std::runtime_error("np_test_timestamp_calendar failed: " + fail_msg);
22870 }
22871
22872 std::cout << " -> tests passed" << std::endl;
22873 }
22874
22875 // ============================================================================
22876 // ROUNDING TESTS
clone (np_test_1_all.cpp:24942)
24932 }
24933
24934 // Test reproducibility
24935 numpy::random::PCG64DXSM rng2(11111);
24936 if (rng2.next_uint64() != val) {
24937 std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : not reproducible";
24938 throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24939 }
24940
24941 // Test clone
24942 auto cloned = rng.clone();
24943 if (cloned->name() != "PCG64DXSM") {
24944 std::cout << " [FAIL] : in np_test_bitgen_pcg64dxsm() : clone name incorrect";
24945 throw std::runtime_error("np_test_bitgen_pcg64dxsm failed");
24946 }
24947
24948 std::cout << " -> tests passed" << std::endl;
24949 }
24950
24951 // ============================================================================
24952 // PHILOX TESTS
idx (np_test_2_all.cpp:7377)
7367 throw std::runtime_error(description);
7368 }
7369
7370 auto [row, col] = to_2d_indices(13, 5);
7371 if (!(row == 2 && col == 3)) {
7372 std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(row == 2 && col == 3)";
7373 std::cout << std::string("[FAIL] ") + description << std::endl;
7374 throw std::runtime_error(description);
7375 }
7376
7377 // std::cout << "Matrix indexing: (2,3) -> " << idx << " -> (" << row << "," << col << ")" << std::endl;
7378
7379 // Test vector operations
7380 double vec[3] = { 3.0, 4.0, 0.0 };
7381 double norm = vector_norm_2(vec, 3);
7382 if (!(std::abs(norm - 5.0) < 1e-10)) {
7383 std::string description = std::string("test_matrix_operations():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(std::abs(norm - 5.0) < 1e-10)";
7384 std::cout << std::string("[FAIL] ") + description << std::endl;
7385 throw std::runtime_error(description);
7386 }
7387 // std::cout << "Vector norm [3,4,0]: " << norm << std::endl;
result (np_test_1_all.cpp:6090)
6080 throw std::runtime_error(description);
6081 }
6082 // std::cout << "Timer restart test passed. Second: " << second_elapsed << " ms" << std::endl;
6083
6084 std::cout << " -> tests passed" << std::endl;
6085}
6086
6087void test_benchmark_result_storageBenchmarkSorting() {
6088 std::cout << "========= test_benchmark_result_storage =======================";
6089
6090 BenchmarkResult result("TestAlgorithm", 1000, 15.5, true, 4096);
6091
6092 if (!(result.algorithm_name == "TestAlgorithm")) {
6093 std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.algorithm_name == \"TestAlgorithm\")";
6094 std::cout << std::string("[FAIL] ") + description << std::endl;
6095 throw std::runtime_error(description);
6096 }
6097 if (!(result.array_size == 1000)) {
6098 std::string description = std::string("test_benchmark_result_storageBenchmarkSorting():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.array_size == 1000)";
6099 std::cout << std::string("[FAIL] ") + description << std::endl;
6100 throw std::runtime_error(description);
shift (np_test_1_all.cpp:2761)
2751 throw std::runtime_error(description);
2752 }
2753 if (!(left_array.getElementAt({3}) == 16384)) {
2754 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(left_array.getElementAt({3}) == 16384)";
2755 std::cout << std::string("[FAIL] ") + description << std::endl;
2756 throw std::runtime_error(description);
2757 }
2758
2759 // std::cout << "[OK] Left shift by array\n";
2760
2761 // Test excessive shift (should result in 0)
2762 auto excessive_left = left_shift(arr, 20); // More than 16 bits
2763 if (!(excessive_left.getElementAt({0}) == 0)) {
2764 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({0}) == 0)";
2765 std::cout << std::string("[FAIL] ") + description << std::endl;
2766 throw std::runtime_error(description);
2767 }
2768 if (!(excessive_left.getElementAt({1}) == 0)) {
2769 std::string description = std::string("testBitShifts():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(excessive_left.getElementAt({1}) == 0)";
2770 std::cout << std::string("[FAIL] ") + description << std::endl;
2771 throw std::runtime_error(description);