From a1342ac0740a67d3e08f3aa8582646bcb364cf76 Mon Sep 17 00:00:00 2001 From: Bela Schaum Date: Wed, 21 Aug 2024 18:35:29 +0200 Subject: [PATCH] Revert exists removing --- src/dataframe/impl/aggregators.cpp | 9 +++++++++ src/dataframe/impl/dataframe.cpp | 4 +++- src/dataframe/interface.h | 3 ++- test/unit/dataframe/interface_test.cpp | 12 ++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/dataframe/impl/aggregators.cpp b/src/dataframe/impl/aggregators.cpp index fbcb55d2d..a455afc50 100644 --- a/src/dataframe/impl/aggregators.cpp +++ b/src/dataframe/impl/aggregators.cpp @@ -114,6 +114,15 @@ get_aggregators() noexcept *std::get_if(&cell)) set.insert(v); return static_cast(set.size()); + }}, + {aggrs[static_cast(aggregator_type::exists)], + empty_double, + [](custom_aggregator::id_type &id, + cell_reference const &cell) -> double + { + auto &b = *std::get_if(&id); + if (is_valid(cell)) b = 1.0; + return b; }}}}}; } diff --git a/src/dataframe/impl/dataframe.cpp b/src/dataframe/impl/dataframe.cpp index f125cf079..42bdab5f9 100644 --- a/src/dataframe/impl/dataframe.cpp +++ b/src/dataframe/impl/dataframe.cpp @@ -94,7 +94,9 @@ dataframe::dataframe(std::shared_ptr other, void valid_unexistent_aggregator(const std::string_view &series, const dataframe::any_aggregator_type &agg) { - if (!agg || *agg != aggregator_type::count) + if (!agg + || (*agg != aggregator_type::count + && *agg != aggregator_type::exists)) error(error_type::series_not_found, series); } diff --git a/src/dataframe/interface.h b/src/dataframe/interface.h index 04e29b181..d37456173 100644 --- a/src/dataframe/interface.h +++ b/src/dataframe/interface.h @@ -27,7 +27,8 @@ enum class aggregator_type : std::uint8_t { max, mean, count, - distinct + distinct, + exists }; enum class sort_type : std::uint8_t { diff --git a/test/unit/dataframe/interface_test.cpp b/test/unit/dataframe/interface_test.cpp index d1f94eb76..f552154f3 100644 --- a/test/unit/dataframe/interface_test.cpp +++ b/test/unit/dataframe/interface_test.cpp @@ -486,11 +486,13 @@ const static auto tests = auto &&pure1c = df->set_aggregate({}, count); auto &&d1c = df->set_aggregate("d1", count); auto &&d1d = df->set_aggregate("d1", distinct); + auto &&d1e = df->set_aggregate("d1", exists); auto &&m1s = df->set_aggregate("m1", sum); auto &&m1mi = df->set_aggregate("m1", min); auto &&m1ma = df->set_aggregate("m1", max); auto &&m1me = df->set_aggregate("m1", mean); auto &&m1c = df->set_aggregate("m1", count); + auto &&m1e = df->set_aggregate("m1", exists); /* auto &&m1t = df->set_aggregate("m1", @@ -524,6 +526,8 @@ auto &&m1t = df->set_aggregate("m1", d1c, m1c, d1d, + d1e, + m1e, m1s, m1ma, m1me, @@ -537,6 +541,8 @@ auto &&m1t = df->set_aggregate("m1", check->*df->get_data(std::size_t{0}, d1c) == 5.0; check->*df->get_data(std::size_t{0}, m1c) == 5.0; check->*df->get_data(std::size_t{0}, d1d) == 1.0; + check->*df->get_data(std::size_t{0}, d1e) == 1.0; + check->*df->get_data(std::size_t{0}, m1e) == 1.0; check->*df->get_data(std::size_t{0}, m1ma) == 88.0; check->*df->get_data(std::size_t{0}, m1me) == 21.85; check->*df->get_data(std::size_t{0}, m1mi) == 2.0; @@ -547,6 +553,8 @@ auto &&m1t = df->set_aggregate("m1", check->*df->get_data(std::size_t{1}, d1c) == 4.0; check->*df->get_data(std::size_t{1}, m1c) == 3.0; check->*df->get_data(std::size_t{1}, d1d) == 1.0; + check->*df->get_data(std::size_t{0}, d1e) == 1.0; + check->*df->get_data(std::size_t{0}, m1e) == 1.0; check->*df->get_data(std::size_t{1}, m1ma) == 7.25; check->*df->get_data(std::size_t{1}, m1me) == 5.0; check->*df->get_data(std::size_t{1}, m1mi) == 3.5; @@ -557,6 +565,8 @@ auto &&m1t = df->set_aggregate("m1", check->*df->get_data(std::size_t{2}, d1c) == 1.0; check->*df->get_data(std::size_t{2}, m1c) == 0.0; check->*df->get_data(std::size_t{2}, d1d) == 1.0; + check->*df->get_data(std::size_t{0}, d1e) == 1.0; + check->*df->get_data(std::size_t{0}, m1e) == 0.0; check ->*std::isnan(std::get( df->get_data(std::size_t{2}, m1ma))) @@ -577,6 +587,8 @@ auto &&m1t = df->set_aggregate("m1", check->*df->get_data(std::size_t{3}, d1c) == 0.0; check->*df->get_data(std::size_t{3}, m1c) == 1.0; check->*df->get_data(std::size_t{3}, d1d) == 0.0; + check->*df->get_data(std::size_t{0}, d1e) == 0.0; + check->*df->get_data(std::size_t{0}, m1e) == 1.0; } | "aggregate multiple dim" |