RecordProxy#
-
class numpy::RecordProxy#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use RecordProxy
RecordProxy obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
NP_RECARRAY.H:41 |
Operators#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
RecordArrayFieldProxy |
NP_RECARRAY.H:44 |
Indexing / Selection#
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
void |
NP_RECARRAY.H:56 |
|
|
void |
NP_RECARRAY.H:65 |
Code Examples#
The following examples are extracted from the test suite.
getField (np_test_2_all.cpp:18700)
18690 void np_test_io_extensions_recfromcsv_dtype_detection() {
18691 std::cout << "========= recfromcsv: automatic dtype detection =======================";
18692
18693 create_csv_file("test_dtypes.csv");
18694
18695 auto data = numpy::io::recfromcsv(csv_test_dir + "test_dtypes.csv");
18696 auto dtype = data.getDType();
18697
18698 // Verify string field detected
18699 auto name_dtype = dtype.getField("name").dtype;
18700 if (name_dtype != numpy::DType::STR32 && name_dtype != numpy::DType::STR16 &&
18701 name_dtype != numpy::DType::STR8 && name_dtype != numpy::DType::STR64) {
18702 std::cout << " [FAIL] : Expected STRING type for name field" << std::endl;
18703 throw std::runtime_error("np_test_io_extensions_recfromcsv_dtype_detection failed: wrong name dtype");
18704 }
18705
18706 // Verify integer field detected
18707 auto age_dtype = dtype.getField("age").dtype;
18708 if (age_dtype != numpy::DType::INT64 && age_dtype != numpy::DType::INT32) {
18709 std::cout << " [FAIL] : Expected INT type for age field";
getRecord (np_test_1_all.cpp:26346)
26336 };
26337 auto dtype = std::make_shared<numpy::StructuredDType>(fields);
26338 numpy::RecordArray arr(dtype, { 2 });
26339
26340 arr.setFieldValue({ 0 }, "id", numpy::int32(1));
26341 arr.setFieldValue({ 0 }, "value", numpy::float64(10.5));
26342 arr.setFieldValue({ 1 }, "id", numpy::int32(2));
26343 arr.setFieldValue({ 1 }, "value", numpy::float64(20.5));
26344
26345 // Test basic comparison operations (indirectly tests createComparisonValue)
26346 auto rec0 = arr.getRecord({ 0 });
26347 auto rec1 = arr.getRecord({ 1 });
26348
26349 // Verify records are different (basic comparison test)
26350 bool passed = true; // If we can get records without error, comparison values work
26351
26352 if (!passed) {
26353 std::cout << " [FAIL] : in np_test_recarray_createComparisonValue() : Create comparison value failed";
26354 throw std::runtime_error("np_test_recarray_createComparisonValue failed");
26355 }
setField (np_test_5_all.cpp:8457)
8447 std::cout << "========= StructuredArray::toString() basic =======================";
8448
8449 std::vector<numpy::StructuredField> fields = {
8450 {"name", numpy::DType::STR_, 0, 10},
8451 {"age", numpy::DType::INT32, 10, 4}
8452 };
8453
8454 auto dtype = std::make_shared<numpy::StructuredDType>(fields);
8455 numpy::StructuredArray arr(dtype, std::vector<size_t>{2});
8456
8457 arr.setField({ 0 }, "name", numpy::StructuredValue(std::string("Alice")));
8458 arr.setField({ 0 }, "age", numpy::StructuredValue(static_cast<int32_t>(30)));
8459 arr.setField({ 1 }, "name", numpy::StructuredValue(std::string("Bob")));
8460 arr.setField({ 1 }, "age", numpy::StructuredValue(static_cast<int32_t>(25)));
8461
8462 std::string result = arr.toString();
8463
8464 // std::cout << "Result:\n" << result << std::endl;
8465
8466 verify_not_empty(result, "StructuredArray toString()");