Back to Documentations

Signature Description Parameters
template<std::floating_point T>
StlVecType<char>
is_nan_mask(const char *col_name, bool not_flag = false) const;
This function returns mask of NaN values. It returns a vector of chars with binary 0’s and 1’s values. A 1 indicates a NaN value.

NOTE: StlVecType is just a std::vector with the applicable allocator for the DataFrame. For example, if you have declared the DataFrame to allocate memory on a particular boundary, then StlVecType is std::vector with an allocator that does so. Otherwise it is just a default std::vector.
T: Type of the col_name column.
col_name: The name of a column or DF_INDEX_COL_NAME
not_flag: If the this is true, the returned result is inversed. In other words a 0 indicates a NaN value and a 1 indicates a valid value.
template<std::floating_point T>
StlVecType<char>
is_infinity_mask(const char *col_name, bool not_flag = false) const;
This function returns mask of Infinity values. It returns a vector of chars with binary 0’s and 1’s values. A 1 indicates an Infinity value.

NOTE: StlVecType is just a std::vector with the applicable allocator for the DataFrame. For example, if you have declared the DataFrame to allocate memory on a particular boundary, then StlVecType is std::vector with an allocator that does so. Otherwise it is just a default std::vector.
T: Type of the col_name column.
col_name: The name of a column or DF_INDEX_COL_NAME
not_flag: If the this is true, the returned result is inversed. In other words a 0 indicates an Infinity value and a 1 indicates a valid value.
template<equality_default_construct T>
StlVecType<char>
is_default_mask(const char *col_name, bool not_flag = false) const;
This function returns mask of default values for type T. It returns a vector of chars with binary 0’s and 1’s values. A 1 indicates a default value.

NOTE: Type T must be default constructible and comparable
NOTE: StlVecType is just a std::vector with the applicable allocator for the DataFrame. For example, if you have declared the DataFrame to allocate memory on a particular boundary, then StlVecType is std::vector with an allocator that does so. Otherwise it is just a default std::vector.
T: Type of the col_name column.
col_name: The name of a column or DF_INDEX_COL_NAME
not_flag: If the this is true, the returned result is inversed. In other words a 0 indicates a default value and a 1 indicates a non-default value.
static void test_is_nan_mask()  {

    std::cout << "\nTesting is_nan_mask( ) ..." << std::endl;

    const double                nval = std::numeric_limits<double>::quiet_NaN();
    ULDataFrame                 df;
    std::vector<unsigned long>  idxvec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    std::vector<double>         dblvec = { 0, 15, -14, 2, 1, 12, 11, 8, 7, 6, 5, 4, 3, 9, 10};
    std::vector<double>         dblvec2 = { 100, 101, nval, 103, 104, 103.9, 106.55, 106.34, 1.8, nval, 112, 111.5, 114, nval, nval};
    std::vector<double>         dblempty { };
    std::vector<double>         allnan = { nval, nval, nval, nval, nval, nval, nval, nval, nval, nval, nval, nval, nval, nval, nval};
    std::vector<std::string>    strvec = { "", "bb", "cc", "ww", "", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "" };

    df.load_data(std::move(idxvec),
                 std::make_pair("dbl_col", dblvec),
                 std::make_pair("dbl_col_2", dblvec2),
                 std::make_pair("Empty Col", dblempty),
                 std::make_pair("All NaN Col", allnan),
                 std::make_pair("str_col", strvec));

    const auto  res1 = df.is_nan_mask<double>("dbl_col");

    assert((res1 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));

    const auto  res2 = df.is_nan_mask<double>("dbl_col", true);

    assert((res2 == std::vector<char>{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));

    const auto  res3 = df.is_nan_mask<double>("dbl_col_2");

    assert((res3 == std::vector<char>{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 }));

    const auto  res4 = df.is_nan_mask<double>("dbl_col_2", true);

    assert((res4 == std::vector<char>{ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 }));

    const auto  res5 = df.is_nan_mask<double>("All NaN Col", true);

    assert((res5 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));
}
// ----------------------------------------------------------------------------

static void test_is_infinity_mask()  {

    std::cout << "\nTesting is_infinity_mask( ) ..." << std::endl;

    const double                ival = std::numeric_limits<double>::infinity();
    ULDataFrame                 df;
    std::vector<unsigned long>  idxvec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    std::vector<double>         dblvec = { 0, 15, -14, 2, 1, 12, 11, 8, 7, 6, 5, 4, 3, 9, 10};
    std::vector<double>         dblvec2 = { 100, 101, ival, 103, 104, 103.9, 106.55, 106.34, 1.8, ival, 112, 111.5, 114, ival, ival};
    std::vector<double>         dblempty { };
    std::vector<double>         allinfinity = { ival, ival, ival, ival, ival, ival, ival, ival, ival, ival, ival, ival, ival, ival, ival };
    std::vector<std::string>    strvec = { "", "bb", "cc", "ww", "", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "" };

    df.load_data(std::move(idxvec),
                 std::make_pair("dbl_col", dblvec),
                 std::make_pair("dbl_col_2", dblvec2),
                 std::make_pair("All Infinity Col", allinfinity),
                 std::make_pair("str_col", strvec));
    df.load_column("Empty Col", std::move(dblempty), nan_policy::dont_pad_with_nans);

    const auto  res1 = df.is_infinity_mask<double>("dbl_col");

    assert((res1 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));

    const auto  res2 = df.is_infinity_mask<double>("dbl_col", true);

    assert((res2 == std::vector<char>{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));

    const auto  res3 = df.is_infinity_mask<double>("dbl_col_2");

    assert((res3 == std::vector<char>{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 }));

    const auto  res4 = df.is_infinity_mask<double>("dbl_col_2", true);

    assert((res4 == std::vector<char>{ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 }));

    const auto  res5 = df.is_infinity_mask<double>("All Infinity Col", true);

    assert((res5 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));

    const auto  res6 = df.is_infinity_mask<double>("Empty Col");

    assert(res6.empty());
}
// ----------------------------------------------------------------------------

static void test_is_default_mask()  {

    std::cout << "\nTesting is_default_mask( ) ..." << std::endl;

    ULDataFrame                 df;
    std::vector<unsigned long>  idxvec = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
    std::vector<double>         dblvec = { 30, 15, -14, 2, 1, 12, 11, 8, 7, 6, 5, 4, 3, 9, 10};
    std::vector<double>         dblvec2 = { 100, 101, 0, 103, 104, 103.9, 106.55, 106.34, 1.8, 0, 112, 111.5, 114, 0, 0};
    std::vector<double>         dblempty { };
    std::vector<double>         alldefault = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    std::vector<std::string>    strvec = { "", "bb", "cc", "ww", "", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "" };

    df.load_data(std::move(idxvec),
                 std::make_pair("dbl_col", dblvec),
                 std::make_pair("dbl_col_2", dblvec2),
                 std::make_pair("All Default Col", alldefault),
                 std::make_pair("str_col", strvec));
    df.load_column("Empty Col", std::move(dblempty), nan_policy::dont_pad_with_nans);

    const auto  res1 = df.is_default_mask<double>("dbl_col");

    assert((res1 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));

    const auto  res2 = df.is_default_mask<double>("dbl_col", true);

    assert((res2 == std::vector<char>{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }));

    const auto  res3 = df.is_default_mask<double>("dbl_col_2");

    assert((res3 == std::vector<char>{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 }));

    const auto  res4 = df.is_default_mask<double>("dbl_col_2", true);

    assert((res4 == std::vector<char>{ 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0 }));

    const auto  res5 = df.is_default_mask<double>("All Default Col", true);

    assert((res5 == std::vector<char>{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }));

    const auto  res6 = df.is_default_mask<double>("Empty Col");

    assert(res6.empty());

    const auto  res7 = df.is_default_mask<std::string>("str_col");

    assert((res7 == std::vector<char>{ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }));
}

C++ DataFrame