Styler#

class numpy::Styler#

numpy C++ class.

Example#

#include <numpy/np_ndarray.h>
using namespace numpy;

// Use Styler
Styler obj;
// ... operations ...

Constructors#

Signature

Location

Example

explicit Styler(const DataFrame& data)

df_styler.h:166

Styler(const Styler& other)

df_styler.h:171

Indexing / Selection#

Signature

Return Type

Location

Example

std::string get_cell_str(size_t row, size_t col) const

std::string

df_styler.h:136

size_t get_col_index(const std::string& col_name) const

size_t

df_styler.h:129

std::string get_column_name(size_t col) const

std::string

df_styler.h:142

std::string get_index_str(size_t row) const

std::string

df_styler.h:139

Math Operations#

Signature

Return Type

Location

Example

std::vector<std::map<std::string, std::string>> export_styles() const

std::vector<std::map<std::string, std::string>>

df_styler.h:501

I/O#

Signature

Return Type

Location

Example

static std::optional<double> to_double(const std::string& s)

static std::optional<double>

df_styler.h:145

std::string to_html(const std::string& table_uuid = "", const std::string& table_attributes = "", bool sparse_index = true, bool sparse_columns = true, bool bold_headers = false, const std::string& caption = "", const std::string& encoding = "utf-8", bool doctype_html = false, bool exclude_styles = false) const

std::string

df_styler.h:529

void to_html(std::ostream& buf, const std::string& table_uuid = "", const std::string& table_attributes = "", bool sparse_index = true, bool sparse_columns = true, bool bold_headers = false, const std::string& caption = "", const std::string& encoding = "utf-8", bool doctype_html = false, bool exclude_styles = false) const

void

df_styler.h:542

std::string to_latex(const std::string& column_format = "", const std::string& position = "", const std::string& position_float = "", bool hrules = false, const std::string& clines = "", const std::string& label = "", const std::string& caption = "", bool sparse_index = true, bool sparse_columns = true, const std::string& multirow_align = "c", const std::string& multicol_align = "r", bool siunitx = false, const std::string& environment = "", const std::string& encoding = "utf-8", bool convert_css = false) const

std::string

df_styler.h:573

void to_latex(std::ostream& buf, const std::string& column_format = "", const std::string& position = "", const std::string& position_float = "", bool hrules = false, const std::string& clines = "", const std::string& label = "", const std::string& caption = "", bool sparse_index = true, bool sparse_columns = true, const std::string& multirow_align = "c", const std::string& multicol_align = "r", bool siunitx = false, const std::string& environment = "", const std::string& encoding = "utf-8", bool convert_css = false) const

void

df_styler.h:592

std::string to_string(bool sparse_index = true, bool sparse_columns = true) const

std::string

df_styler.h:616

View

void to_string(std::ostream& buf, bool sparse_index = true, bool sparse_columns = true) const

void

df_styler.h:622

View

Other Methods#

Signature

Return Type

Location

Example

Styler& apply(ColumnStyleFunc func, std::optional<int> axis = 0, const StyleSubset& subset =

Styler&

df_styler.h:190

Styler& background_gradient(const std::string& cmap = "PuBu", double low = 0.0, double high = 0.0, std::optional<int> axis = 0, const StyleSubset& subset =

Styler&

df_styler.h:304

Styler& bar(const StyleSubset& subset =

Styler&

df_styler.h:344

Styler& clear()

Styler&

df_styler.h:494

View

Styler& concat(const Styler& other)

Styler&

df_styler.h:636

const DataFrame& data() const

const DataFrame&

df_styler.h:652

View

void ensure_style_matrices()

void

df_styler.h:126

static std::string escape_html(const std::string& str)

static std::string

df_styler.h:148

Styler& format(const std::string& formatter = "", const StyleSubset& subset =

Styler&

df_styler.h:369

View

Styler& format(const std::map<std::string, std::string>& formatters, const std::string& na_rep = "", int precision = -1, bool escape = true)

Styler&

df_styler.h:379

View

Styler& hide(const StyleSubset& subset =

Styler&

df_styler.h:480

Styler& highlight_between(const StyleSubset& subset =

Styler&

df_styler.h:259

Styler& highlight_max(const StyleSubset& subset =

Styler&

df_styler.h:228

Styler& highlight_min(const StyleSubset& subset =

Styler&

df_styler.h:242

Styler& highlight_null(const std::string& color = "red", const StyleSubset& subset =

Styler&

df_styler.h:215

Styler& highlight_quantile(const StyleSubset& subset =

Styler&

df_styler.h:279

static std::string interpolate_color(double normalized, const std::string& low_color, const std::string& high_color)

static std::string

df_styler.h:151

Styler& map(CellStyleFunc func, const StyleSubset& subset =

Styler&

df_styler.h:201

static std::tuple<int, int, int> parse_color(const std::string& color)

static std::tuple<int, int, int>

df_styler.h:156

auto pipe(Func func) -> decltype(func(\*this))

auto

df_styler.h:645

std::string render() const

std::string

df_styler.h:657

std::pair<std::vector<size_t>, std::vector<size_t>> resolve_subset( const StyleSubset& subset) const

std::pair<std::vector<size_t>, std::vector<size_t>>

df_styler.h:132

static std::string rgb_to_hex(int r, int g, int b)

static std::string

df_styler.h:159

Styler& set_caption(const std::string& caption)

Styler&

df_styler.h:433

Styler& set_properties(const std::map<std::string, std::string>& props, const StyleSubset& subset =

Styler&

df_styler.h:395

Styler& set_sticky(std::optional<int> axis = 0, std::optional<int> pixel_size = std::nullopt, const std::vector<int>& levels =

Styler&

df_styler.h:463

Styler& set_table_attributes(const std::string& attributes)

Styler&

df_styler.h:417

Styler& set_table_styles( const std::vector<std::pair<std::string, std::string>>& table_styles, std::optional<int> axis = std::nullopt, bool overwrite = false)

Styler&

df_styler.h:406

Styler& set_td_classes(const std::vector<std::vector<std::string>>& classes)

Styler&

df_styler.h:425

Styler& set_tooltips(const std::vector<std::vector<std::string>>& ttips, const std::string& props = "", const std::string& css_class = "")

Styler&

df_styler.h:443

Styler& set_uuid(const std::string& uuid)

Styler&

df_styler.h:453

Styler& text_gradient(const std::string& cmap = "PuBu", double low = 0.0, double high = 0.0, std::optional<int> axis = 0, const StyleSubset& subset =

Styler&

df_styler.h:318

Styler& use(const std::vector<std::map<std::string, std::string>>& styles)

Styler&

df_styler.h:509

Code Examples#

The following examples are extracted from the test suite.

to_string (np_test_1_all.cpp:454)
444    // Modify through different views
445    view1.setElementAt({0, 0}, 100);
446    view2.setElementAt({2, 1}, 200);  // This is (1, 2) in original
447    view3.setElementAt({0, 0}, 300);  // This is (1, 1) in original
448
449    // std::cout << "After modifications through multiple views:" << std::endl;
450    //original.printArray();
451
452    // Verify all changes are reflected
453    if (!(original.getElementAt({0, 0}) == 100)) {
454        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455        std::cout << std::string("[FAIL] ") + description << std::endl;
456        throw std::runtime_error(description);
457    }
458    if (!(original.getElementAt({1, 2}) == 200)) {
459        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460        std::cout << std::string("[FAIL] ") + description << std::endl;
461        throw std::runtime_error(description);
462    }
463    if (!(original.getElementAt({1, 1}) == 300)) {
464        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";
to_string (np_test_1_all.cpp:454)
444    // Modify through different views
445    view1.setElementAt({0, 0}, 100);
446    view2.setElementAt({2, 1}, 200);  // This is (1, 2) in original
447    view3.setElementAt({0, 0}, 300);  // This is (1, 1) in original
448
449    // std::cout << "After modifications through multiple views:" << std::endl;
450    //original.printArray();
451
452    // Verify all changes are reflected
453    if (!(original.getElementAt({0, 0}) == 100)) {
454        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({0, 0}) == 100)";
455        std::cout << std::string("[FAIL] ") + description << std::endl;
456        throw std::runtime_error(description);
457    }
458    if (!(original.getElementAt({1, 2}) == 200)) {
459        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 2}) == 200)";
460        std::cout << std::string("[FAIL] ") + description << std::endl;
461        throw std::runtime_error(description);
462    }
463    if (!(original.getElementAt({1, 1}) == 300)) {
464        std::string description = std::string("testAdvancedViewLifecycle():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(original.getElementAt({1, 1}) == 300)";
clear (np_test_2_all.cpp:4161)
4151        auto array = createFloat32Array({ 10, 10 }, static_cast<float>(i));
4152        temp_arrays.push_back(array);
4153
4154        auto view = array.view();
4155        temp_views.push_back(view);
4156      }
4157
4158      // std::cout << "Created 100 arrays and 100 views" << std::endl;
4159
4160      // Clear all arrays (views will keep memory alive)
4161      temp_arrays.clear();
4162      // std::cout << "Cleared original arrays" << std::endl;
4163
4164      // Verify views still work
4165      if (!(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)) {
4166          std::string description = std::string("testMemoryLeakPrevention():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(temp_views[50].getElementAt({ 5, 5 }) == 50.0f)";
4167          std::cout << std::string("[FAIL] ") + description << std::endl;
4168          throw std::runtime_error(description);
4169      }
4170      // std::cout << "[OK] Views still valid after originals cleared";
data (np_test_1_all.cpp:2084)
2074    }
2075    if (!(derived_ptr->extra == 2)) {
2076        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(derived_ptr->extra == 2)";
2077        std::cout << std::string("[FAIL] ") + description << std::endl;
2078        throw std::runtime_error(description);
2079    }
2080
2081    // Test 6: Large object handling
2082    struct LargeObject {
2083        std::vector<double> data;
2084        LargeObject() : data(10000, 3.14159) {}  // Large object
2085    };
2086
2087    LargeObject large;
2088    object_ large_obj(large);  // Should handle large objects
2089    if (!(!large_obj.is_null())) {
2090        std::string description = std::string("testObjectHolderEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(!large_obj.is_null())";
2091        std::cout << std::string("[FAIL] ") + description << std::endl;
2092        throw std::runtime_error(description);
2093    }
2094    if (!(large_obj.is_type<LargeObject>())) {
format (main.cpp:22)
12int main() {
13  // Automatically log all output to temp/test_output.log
14  numpy::TestLogger logger("temp/test_output.log");
15
16  int res = 0;
17  int res1 = 0;
18  std::string resS = "";
19
20  // call all the tests
21  res1 = numpy_tests::np_test_main();
22  resS += std::format("             np_test_main: {}  errors\n", res1);
23  res += res1;
24
25  std::cout << "\n------------------------- main --------------------------------------------\n";
26  std::cout << std::endl << "All tests completed. Nb errors = " << res << std::endl;
27  std::cout << "Details: \n" << resS;
28  std::cout << "\n---------------------------------------------------------------------------\n";
29  return res;
30}
format (main.cpp:22)
12int main() {
13  // Automatically log all output to temp/test_output.log
14  numpy::TestLogger logger("temp/test_output.log");
15
16  int res = 0;
17  int res1 = 0;
18  std::string resS = "";
19
20  // call all the tests
21  res1 = numpy_tests::np_test_main();
22  resS += std::format("             np_test_main: {}  errors\n", res1);
23  res += res1;
24
25  std::cout << "\n------------------------- main --------------------------------------------\n";
26  std::cout << std::endl << "All tests completed. Nb errors = " << res << std::endl;
27  std::cout << "Details: \n" << resS;
28  std::cout << "\n---------------------------------------------------------------------------\n";
29  return res;
30}