Skip to content

Commit

Permalink
Revert exists removing
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed Aug 21, 2024
1 parent d581beb commit a1342ac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/dataframe/impl/aggregators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ get_aggregators() noexcept
*std::get_if<const std::string *>(&cell))
set.insert(v);
return static_cast<double>(set.size());
}},
{aggrs[static_cast<std::size_t>(aggregator_type::exists)],
empty_double,
[](custom_aggregator::id_type &id,
cell_reference const &cell) -> double
{
auto &b = *std::get_if<double>(&id);
if (is_valid(cell)) b = 1.0;
return b;
}}}}};
}

Expand Down
4 changes: 3 additions & 1 deletion src/dataframe/impl/dataframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ dataframe::dataframe(std::shared_ptr<const data_source> 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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/dataframe/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ enum class aggregator_type : std::uint8_t {
max,
mean,
count,
distinct
distinct,
exists
};

enum class sort_type : std::uint8_t {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/dataframe/interface_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -524,6 +526,8 @@ auto &&m1t = df->set_aggregate("m1",
d1c,
m1c,
d1d,
d1e,
m1e,
m1s,
m1ma,
m1me,
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<double>(
df->get_data(std::size_t{2}, m1ma)))
Expand All @@ -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" |
Expand Down

0 comments on commit a1342ac

Please sign in to comment.