JsonValue#
-
class pandas::JsonValue#
pandas C++ class.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use JsonValue
JsonValue obj;
// ... operations ...
Constructors#
Type Checking#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
json.h:63 |
|
|
bool |
json.h:59 |
|
|
bool |
json.h:61 |
|
|
bool |
json.h:60 |
|
|
bool |
json.h:58 |
|
|
bool |
json.h:64 |
|
|
bool |
json.h:62 |
Code Examples#
The following examples are extracted from the test suite.
JsonValue (pd_test_5_all.cpp:81168)
81158void case_1_default_is_null(int& local_fail) {
81159 std::cout << "-- case_1_default_is_null\n";
81160 JsonValue v;
81161 pandas_tests::check(v.is_null(),
81162 "case_1_default_is_null.is_null()", local_fail);
81163}
81164
81165void case_2_bool_true_false(int& local_fail) {
81166 std::cout << "-- case_2_bool_true_false\n";
81167 check_str("case_2_bool_true_false.true_str()", "True",
81168 [] { return PIO::json_value_to_string(JsonValue(true)); }, local_fail);
81169 check_str("case_2_bool_true_false.false_str()", "False",
81170 [] { return PIO::json_value_to_string(JsonValue(false)); }, local_fail);
81171}
81172
81173void case_3_int64_range(int& local_fail) {
81174 std::cout << "-- case_3_int64_range\n";
81175 check_str("case_3_int64_range.zero()", "0",
81176 [] { return PIO::json_value_to_string(JsonValue(int64_t{0})); },
81177 local_fail);
81178 check_str("case_3_int64_range.neg()", "-12345",
JsonValue (pd_test_5_all.cpp:81168)
81158void case_1_default_is_null(int& local_fail) {
81159 std::cout << "-- case_1_default_is_null\n";
81160 JsonValue v;
81161 pandas_tests::check(v.is_null(),
81162 "case_1_default_is_null.is_null()", local_fail);
81163}
81164
81165void case_2_bool_true_false(int& local_fail) {
81166 std::cout << "-- case_2_bool_true_false\n";
81167 check_str("case_2_bool_true_false.true_str()", "True",
81168 [] { return PIO::json_value_to_string(JsonValue(true)); }, local_fail);
81169 check_str("case_2_bool_true_false.false_str()", "False",
81170 [] { return PIO::json_value_to_string(JsonValue(false)); }, local_fail);
81171}
81172
81173void case_3_int64_range(int& local_fail) {
81174 std::cout << "-- case_3_int64_range\n";
81175 check_str("case_3_int64_range.zero()", "0",
81176 [] { return PIO::json_value_to_string(JsonValue(int64_t{0})); },
81177 local_fail);
81178 check_str("case_3_int64_range.neg()", "-12345",
JsonValue (pd_test_5_all.cpp:81168)
81158void case_1_default_is_null(int& local_fail) {
81159 std::cout << "-- case_1_default_is_null\n";
81160 JsonValue v;
81161 pandas_tests::check(v.is_null(),
81162 "case_1_default_is_null.is_null()", local_fail);
81163}
81164
81165void case_2_bool_true_false(int& local_fail) {
81166 std::cout << "-- case_2_bool_true_false\n";
81167 check_str("case_2_bool_true_false.true_str()", "True",
81168 [] { return PIO::json_value_to_string(JsonValue(true)); }, local_fail);
81169 check_str("case_2_bool_true_false.false_str()", "False",
81170 [] { return PIO::json_value_to_string(JsonValue(false)); }, local_fail);
81171}
81172
81173void case_3_int64_range(int& local_fail) {
81174 std::cout << "-- case_3_int64_range\n";
81175 check_str("case_3_int64_range.zero()", "0",
81176 [] { return PIO::json_value_to_string(JsonValue(int64_t{0})); },
81177 local_fail);
81178 check_str("case_3_int64_range.neg()", "-12345",
is_int (pd_test_5_all.cpp:81116)
81106static void check_lookup_int(const std::string& label,
81107 const JsonObject& root,
81108 const std::vector<std::string>& path,
81109 int64_t expected_int,
81110 int& local_fail) {
81111 bool ok = false;
81112 std::string err;
81113 try {
81114 const JsonValue* hit = PIO::lookup_path(root, path);
81115 if (hit && hit->is_int() && std::get<int64_t>(hit->v) == expected_int) {
81116 ok = true;
81117 }
81118 } catch (const std::exception& e) {
81119 err = std::string("THREW: ") + e.what();
81120 }
81121 pandas_tests::check(ok, label, local_fail);
81122 if (!ok && !err.empty()) std::cout << " " << err << "\n";
81123}
81124
81125static void check_lookup_object(const std::string& label,
is_null (pd_test_5_all.cpp:71470)
71460 bool ok = (got == expected);
71461 pandas_tests::check(ok, label, local_fail);
71462 if (!ok) {
71463 std::cout << " expected: [" << expected << "]\n"
71464 << " got: [" << got << "]\n";
71465 }
71466 return ok;
71467}
71468
71469static numpy::object_ obj_none() {
71470 return numpy::object_(); // default-constructed -> is_null() == true
71471}
71472
71473static numpy::object_ obj_nan() {
71474 return numpy::object_(std::numeric_limits<double>::quiet_NaN());
71475}
71476
71477static numpy::object_ obj_int(int64_t v) {
71478 return numpy::object_(v);
71479}
is_object (pd_test_3_all.cpp:626)
616 throw std::runtime_error("pd_test_3_all_index_dtype_checks failed: int is_numeric");
617 }
618 if (!int_dtype.is_integer()) {
619 std::cout << " [FAIL] : in pd_test_3_all_index_dtype_checks() : int should be integer" << std::endl;
620 throw std::runtime_error("pd_test_3_all_index_dtype_checks failed: int is_integer");
621 }
622 if (int_dtype.is_floating()) {
623 std::cout << " [FAIL] : in pd_test_3_all_index_dtype_checks() : int should not be floating" << std::endl;
624 throw std::runtime_error("pd_test_3_all_index_dtype_checks failed: int is_floating");
625 }
626 if (int_dtype.is_object()) {
627 std::cout << " [FAIL] : in pd_test_3_all_index_dtype_checks() : int should not be object" << std::endl;
628 throw std::runtime_error("pd_test_3_all_index_dtype_checks failed: int is_object");
629 }
630
631 // Test with float index
632 pandas::IndexDtype<double> float_dtype;
633 if (!float_dtype.is_numeric()) {
634 std::cout << " [FAIL] : in pd_test_3_all_index_dtype_checks() : float should be numeric" << std::endl;
635 throw std::runtime_error("pd_test_3_all_index_dtype_checks failed: float is_numeric");
636 }