DatetimeDtype#
-
class numpy::DatetimeDtype#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use DatetimeDtype
DatetimeDtype obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_datetime_dtype.h:47 |
|
|
df_datetime_dtype.h:63 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
size_t |
df_datetime_dtype.h:98 |
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
df_datetime_dtype.h:134 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
df_datetime_dtype.h:106 |
|
|
bool |
df_datetime_dtype.h:162 |
|
|
std::string |
df_datetime_dtype.h:78 |
|
|
numpy::DType |
df_datetime_dtype.h:91 |
|
|
std::string |
df_datetime_dtype.h:173 |
|
|
const std::type_info& |
df_datetime_dtype.h:113 |
|
|
std::shared_ptr<numpy::TimezoneInfo> |
df_datetime_dtype.h:127 |
|
|
numpy::DateTimeUnit |
df_datetime_dtype.h:120 |
|
|
std::string |
df_datetime_dtype.h:141 |
|
|
DatetimeDtype |
df_datetime_dtype.h:193 |
|
|
DatetimeDtype |
df_datetime_dtype.h:200 |
|
|
DatetimeDtype |
df_datetime_dtype.h:186 |
|
|
DatetimeDtype |
df_datetime_dtype.h:207 |
Code Examples#
The following examples are extracted from the test suite.
itemsize (np_test_2_all.cpp:3540)
3530 }
3531
3532 // Test size
3533 if (!(size(arr) == 24)) {
3534 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(size(arr) == 24)";
3535 std::cout << std::string("[FAIL] ") + description << std::endl;
3536 throw std::runtime_error(description);
3537 }
3538
3539 // Test itemsize
3540 if (!(itemsize(arr) == sizeof(double))) {
3541 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(itemsize(arr) == sizeof(double))";
3542 std::cout << std::string("[FAIL] ") + description << std::endl;
3543 throw std::runtime_error(description);
3544 }
3545
3546 // Test nbytes
3547 if (!(nbytes(arr) == 24 * sizeof(double))) {
3548 std::string description = std::string("testArrayInfo():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(nbytes(arr) == 24 * sizeof(double))";
3549 std::cout << std::string("[FAIL] ") + description << std::endl;
3550 throw std::runtime_error(description);
matches (np_test_1_all.cpp:26699)
26689 std::cout << std::string("[FAIL] ") + description << std::endl;
26690 throw std::runtime_error(description);
26691 }
26692 // std::cout << " ✓ load_library() (stub)" << std::endl;
26693 }
26694
26695 // Test ndpointer
26696 {
26697 auto ptr_desc = numpy::ctypeslib::ndpointer<double>(2, { 10, 10 });
26698 auto arr = NDArray<double>({ 10, 10 }, 0.0);
26699 bool matches = ptr_desc.matches(arr);
26700 if (!(matches)) {
26701 std::string description = std::string("test_ctypes_interop():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(matches)";
26702 std::cout << std::string("[FAIL] ") + description << std::endl;
26703 throw std::runtime_error(description);
26704 }
26705 // std::cout << " ✓ ndpointer()" << std::endl;
26706 }
26707
26708 // std::cout << " [PASS] Sub-phase 6D complete (4 functions tested)" << std::endl;
26709 }
name (np_test_1_all.cpp:24865)
24855 uint64_t before_restore = rng.next_uint64();
24856 rng.set_state(state);
24857 uint64_t after_restore = rng.next_uint64();
24858
24859 if (before_restore != after_restore) {
24860 std::cout << " [FAIL] : in np_test_bitgen_mt19937() : state restore failed";
24861 throw std::runtime_error("np_test_bitgen_mt19937 failed: state");
24862 }
24863
24864 // Test name
24865 if (rng.name() != "MT19937") {
24866 std::cout << " [FAIL] : in np_test_bitgen_mt19937() : incorrect name";
24867 throw std::runtime_error("np_test_bitgen_mt19937 failed: name");
24868 }
24869
24870 std::cout << " -> tests passed" << std::endl;
24871 }
24872
24873 // ============================================================================
24874 // PCG64 TESTS
24875 // ============================================================================
type (np_test_1_all.cpp:2240)
2230 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 1}).is_type<std::string>())";
2231 std::cout << std::string("[FAIL] ") + description << std::endl;
2232 throw std::runtime_error(description);
2233 }
2234 if (!(multi_array.getElementAt({0, 2}).is_type<double>())) {
2235 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(multi_array.getElementAt({0, 2}).is_type<double>())";
2236 std::cout << std::string("[FAIL] ") + description << std::endl;
2237 throw std::runtime_error(description);
2238 }
2239
2240 // Test 4: Arrays with all same type (homogeneous)
2241 NDArray<object_> homo_array = createObjectZeros({5});
2242 for (size_t i = 0; i < 5; ++i) {
2243 homo_array.setElementAt({i}, object_(static_cast<int>(i * 10)));
2244 }
2245
2246 // Verify all are same type
2247 for (size_t i = 0; i < 5; ++i) {
2248 object_ obj = homo_array.getElementAt({i});
2249 if (!(obj.is_type<int>())) {
2250 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";
tz (np_test_5_all.cpp:22214)
22204 }
22205 }
22206
22207 if (errors == 0) {
22208 std::cout << "np_test_timedelta_edge_cases -> tests passed" << std::endl;
22209 }
22210 return errors;
22211}
22212
22213} // namespace numpy_tests_timedelta
22214
22215// =============================================================================
22216// Main Test Runner
22217// =============================================================================
22218int np_test_timedelta_main() {
22219 int errors = 0;
22220
22221 errors += numpy_tests_timedelta::np_test_timedelta_constructors();
22222 errors += numpy_tests_timedelta::np_test_timedelta_static_factories();
22223 errors += numpy_tests_timedelta::np_test_timedelta_components();
22224 errors += numpy_tests_timedelta::np_test_timedelta_total_conversions();