Skip to content

Commit

Permalink
Add GetDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
BUYT-1 authored and polyntsov committed Dec 4, 2023
1 parent 309a08c commit f447dde
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/algorithms/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,14 @@ std::unordered_set<std::string_view> Algorithm::GetPossibleOptions() const {
return possible_options;
}

std::string_view Algorithm::GetDescription(std::string_view option_name) const {
auto it = possible_options_.find(option_name);
if (it == possible_options_.end()) {
return "";
} else {
return it->second->GetDescription();
}
}

} // namespace algos

1 change: 1 addition & 0 deletions src/core/algorithms/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Algorithm {
std::type_index GetTypeIndex(std::string_view option_name) const;

[[nodiscard]] std::unordered_set<std::string_view> GetPossibleOptions() const;
[[nodiscard]] std::string_view GetDescription(std::string_view option_name) const;
};

} // namespace algos
1 change: 1 addition & 0 deletions src/core/config/ioption.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class IOption {
virtual void Unset() = 0;
[[nodiscard]] virtual bool IsSet() const = 0;
[[nodiscard]] virtual std::string_view GetName() const = 0;
[[nodiscard]] virtual std::string_view GetDescription() const = 0;
[[nodiscard]] virtual std::type_index GetTypeIndex() const = 0;
virtual ~IOption() = default;
};
Expand Down
2 changes: 2 additions & 0 deletions src/python_bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ PYBIND11_MODULE(desbordante, module) {
"Get names of options the algorithm may request")
.def("set_option", &PyAlgorithmBase::SetOption, "option_name"_a,
"option_value"_a = pybind11::none(), "Set option value")
.def("get_description", &PyAlgorithmBase::GetDescription, "option_name"_a,
"Get description of an option")
.def("get_option_type", &PyAlgorithmBase::GetOptionType, "option_name"_a,
"Get info about the option's type")
.def("execute", &PyAlgorithmBase::Execute, "Process data");
Expand Down
4 changes: 4 additions & 0 deletions src/python_bindings/py_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ py::tuple PyAlgorithmBase::GetOptionType(std::string_view option_name) const {
return GetPyType(type_index);
}

std::string_view PyAlgorithmBase::GetDescription(std::string_view option_name) const {
return algorithm_->GetDescription(option_name);
}

void PyAlgorithmBase::LoadProvidedData(pybind11::kwargs const& kwargs, InputTable table) {
algorithm_->UnsetOption(kTable);
Configure(kwargs, std::move(table));
Expand Down
1 change: 1 addition & 0 deletions src/python_bindings/py_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PyAlgorithmBase {

[[nodiscard]] std::unordered_set<std::string_view> GetPossibleOptions() const;

[[nodiscard]] std::string_view GetDescription(std::string_view option_name) const;
[[nodiscard]] pybind11::tuple GetOptionType(std::string_view option_name) const;

// For pandas dataframes
Expand Down

0 comments on commit f447dde

Please sign in to comment.