PartialKeyResult#

class pandas::PartialKeyResult#

pandas C++ class.

Example#

#include <pandas/pandas.h>
using namespace pandas;

// Use PartialKeyResult
PartialKeyResult obj;
// ... operations ...

Type Checking#

Signature

Return Type

Location

Example

bool is_single_level() const { return single_index.has_value()

bool

pd_multiindex.h:3273

View

Code Examples#

The following examples are extracted from the test suite.

is_single_level (pd_test_3_all.cpp:26357)
26347    std::vector<std::vector<std::string>> arrays = {
26348        {"foo", "foo", "bar", "bar"},
26349        {"one", "two", "one", "two"}
26350    };
26351    std::vector<std::optional<std::string>> names = {"first", "second"};
26352    auto mi = ::pandas::MultiIndex::from_arrays<std::string>(arrays, names);
26353
26354    auto pk = ::pandas::select_by_first_level(mi,"foo");
26355    if (pk.matched_indices.size() != 2) throw std::runtime_error("Expected 2 matches for 'foo'");
26356    if (pk.matched_indices[0] != 0 || pk.matched_indices[1] != 1) throw std::runtime_error("Wrong indices for 'foo'");
26357    if (!pk.is_single_level()) throw std::runtime_error("Expected single level for 2-level MI");
26358    auto idx = *pk.single_index;
26359    if (idx.size() != 2) throw std::runtime_error("Expected index size 2");
26360    if (idx[0] != "one" || idx[1] != "two") throw std::runtime_error("Wrong index values");
26361    if (!idx.name().has_value() || *idx.name() != "second") throw std::runtime_error("Wrong index name");
26362    std::cout << "    PASSED" << std::endl;
26363}
26364
26365void pd_test_multiindex_partial_key_bar() {
26366    std::cout << "  Testing select_by_first_level 2-level 'bar'..." << std::endl;
26367    std::vector<std::vector<std::string>> arrays = {