IndexDtype#

class numpy::IndexDtype#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use IndexDtype
IndexDtype obj;
// ... operations ...

Indexing / Selection#

Signature

Return Type

Location

Example

size_t itemsize() const override

size_t

df_index_dtype.h:109

View

Type Checking#

Signature

Return Type

Location

Example

bool is_datetime() const

bool

df_index_dtype.h:213

bool is_floating() const

bool

df_index_dtype.h:199

bool is_integer() const

bool

df_index_dtype.h:192

bool is_nullable() const override

bool

df_index_dtype.h:138

bool is_numeric() const

bool

df_index_dtype.h:185

View

bool is_object() const

bool

df_index_dtype.h:206

bool is_timedelta() const

bool

df_index_dtype.h:220

Other Methods#

Signature

Return Type

Location

Example

std::string inferred_type() const

std::string

df_index_dtype.h:166

std::string kind() const override

std::string

df_index_dtype.h:118

std::string name() const override

std::string

df_index_dtype.h:39

View

numpy::DType numpy_dtype() const override

numpy::DType

df_index_dtype.h:75

std::string repr() const override

std::string

df_index_dtype.h:154

const std::type_info& type() const override

const std::type_info&

df_index_dtype.h:146

View

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);
is_numeric (np_test_1_all.cpp:7511)
7501    std::cout << " -> tests passed" << std::endl;
7502}
7503
7504void testNumericConversionStringTypes() {
7505    std::cout << "========= testNumericStringOperationsStringTypes =======================";
7506
7507    str32 num_str1("123.45");
7508    str32 num_str2("67.89");
7509    str32 not_num("hello");
7510
7511    // std::cout << "String '" << num_str1 << "' is numeric: " << is_numeric(num_str1) << std::endl;
7512    // std::cout << "String '" << not_num << "' is numeric: " << is_numeric(not_num) << std::endl;
7513
7514    if (is_numeric(num_str1)) {
7515        double val1 = to_numeric(num_str1);
7516        // std::cout << "Numeric value of '" << num_str1 << "': " << val1 << std::endl;
7517    }
7518
7519    if (is_numeric(num_str2)) {
7520        double val2 = to_numeric(num_str2);
7521        // std::cout << "Numeric value of '" << num_str2 << "': " << val2 << std::endl;
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>())";