From 530541015b88f021e9230cc20926c546a21add78 Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Mon, 19 Dec 2022 13:11:34 -0500 Subject: [PATCH] fixed the doc for get_data() --- docs/HTML/get_data.html | 97 +++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/docs/HTML/get_data.html b/docs/HTML/get_data.html index 6b289828d..483a06342 100644 --- a/docs/HTML/get_data.html +++ b/docs/HTML/get_data.html @@ -86,56 +86,59 @@ -
static void test_groupby_edge()  {
-
-    std::cout << "\nTesting groupby( ) ..." << std::endl;
-
-    MyDataFrame                df;
-    std::vector<unsigned long>  idxvec =
-        { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL,
-          10UL, 15UL, 14UL };
-    std::vector<double>         dblvec =
-        { 0.0, 15.0, -14.0, 2.0, 1.0, 12.0, 11.0, 8.0, 7.0, 6.0, 5.0, 4.0,
-          3.0, 9.0, 10.0};
-    std::vector<double>         dblvec2 =
-        { 100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.55, 107.34, 1.8,
-          111.0, 112.0, 113.0, 114.0, 115.0, 116.0};
-    std::vector<int>            intvec = { 1, 2, 3, 4, 5, 8, 6, 7, 11, 14, 9 };
-    std::vector<std::string>    strvec =
-        { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk",
-          "ll", "mm", "nn", "oo" };
-    dblvec2.resize(1);
-    dblvec.resize(1);
-    strvec.resize(1);
-    intvec.resize(1);
-    idxvec.resize(1); // make this greater then one to fix coredump with hack
-    df.load_data(std::move(idxvec),
-                 std::make_pair("dbl_col", dblvec),
-                 std::make_pair("dbl_col_2", dblvec2),
-                 std::make_pair("str_col", strvec));
-    df.load_column("int_col", std::move(intvec),
-                   nan_policy::dont_pad_with_nans);
-
-    FactorizeVisitor<double>    fact([] (const double &f) -> bool {
-                                         return (f > 11106.0 && f < 114.0);
-                                     });
-    df.load_column("bool_col",
-                   df.single_act_visit<double>("dbl_col_2", fact).get_result());
-
-    df.write<std::ostream, std::string, double, int, bool>
-        (std::cout, io_format::csv2);
-
-    auto bool_df = df.groupby1<bool>(
-        "bool_col",
-        LastVisitor<MyDataFrame::IndexType, MyDataFrame::IndexType>(),
-        std::make_tuple("dbl_col_2", "sum_dbl2", SumVisitor<double>()),
-        std::make_tuple("dbl_col_2", "cnt_dbl2", CountVisitor<double>()));
-    bool_df.write<std::ostream, double, std::size_t, bool>
-        (std::cout, io_format::csv2);
+
static void test_get_data()  {
+
+    std::cout << "\nTesting get_[data|view]() ..." << std::endl;
+
+    std::vector<unsigned long>  idx =
+        { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466 };
+    std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
+    std::vector<double> d2 = { 8, 9, 10, 11, 12, 13, 14, 20, 22, 23, 30, 31, 32, 1.89 };
+    std::vector<double> d3 = { 15, 16, 17, 18, 19, 20, 21, 0.34, 1.56, 0.34, 2.3, 0.1, 0.89, 0.45 };
+    std::vector<int>    i1 = { 22, 23, 24, 25, 99, 100, 101, 3, 2 };
+    MyDataFrame         df;
+
+    df.load_data(std::move(idx),
+                 std::make_pair("col_1", d1),
+                 std::make_pair("col_2", d2),
+                 std::make_pair("col_3", d3),
+                 std::make_pair("col_4", i1));
+
+    auto    df2 = df.get_data<double, int>({ "col_1", "col_4"});
+
+    assert((! df2.has_column("col_2")));
+    assert((! df2.has_column("col_3")));
+    assert((df2.get_column<double>("col_1")[11] == 12));
+    assert((df2.get_column<int>("col_4")[8] == 2));
+    assert((df2.get_index()[3] == 123453));
+
+    const MyDataFrame                   &const_df = df;
+    DataFrameView<unsigned long>        df3 = df.get_view<double, int>({ "col_1", "col_4"});
+    DataFrameConstView<unsigned long>   const_df3 = const_df.get_view<double, int>({ "col_1", "col_4"});
+
+    assert((! df3.has_column("col_2")));
+    assert((! df3.has_column("col_3")));
+    assert((df3.get_column<double>("col_1")[11] == 12));
+    assert((df3.get_column<int>("col_4")[8] == 2));
+    assert((df3.get_index()[3] == 123453));
+
+    df3.get_index()[3] = 100;
+    df3.get_column<int>("col_4")[8] = 101;
+    df3.get_column<double>("col_1")[11] = 102.2;
+
+    assert((df3.get_column<double>("col_1")[11] == 102.2));
+    assert((df3.get_column<int>("col_4")[8] == 101));
+    assert((df3.get_index()[3] == 100));
+    assert((df.get_column<double>("col_1")[11] == 102.2));
+    assert((df.get_column<int>("col_4")[8] == 101));
+    assert((df.get_index()[3] == 100));
+
+    assert((const_df3.get_column<double>("col_1")[11] == 102.2));
+    assert((const_df3.get_column<int>("col_4")[8] == 101));
+    assert((const_df3.get_index()[3] == 100));
 }
 
- C++ DataFrame