Styler#
-
class pandas::Styler#
Styling class for DataFrame rendering.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use Styler
Styler obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
pd_styler.h:167 |
|
|
pd_styler.h:172 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::string |
pd_styler.h:137 |
|
|
size_t |
pd_styler.h:130 |
|
|
std::string |
pd_styler.h:143 |
|
|
std::string |
pd_styler.h:140 |
Missing Data#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static std::string |
pd_styler.h:152 |
Aggregation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
Styler& |
pd_styler.h:191 |
|
|
Styler& |
pd_styler.h:202 |
|
|
auto |
pd_styler.h:646 |
Combining#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
Styler& |
pd_styler.h:637 |
I/O#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
static std::optional<double> |
pd_styler.h:146 |
|
|
std::string |
pd_styler.h:530 |
|
|
void |
pd_styler.h:543 |
|
|
std::string |
pd_styler.h:574 |
|
|
void |
pd_styler.h:593 |
|
|
std::string |
pd_styler.h:617 |
|
|
void |
pd_styler.h:623 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
Styler& |
pd_styler.h:305 |
|
|
Styler& |
pd_styler.h:345 |
|
|
Styler& |
pd_styler.h:495 |
|
|
const DataFrame& |
pd_styler.h:653 |
|
|
void |
pd_styler.h:127 |
|
|
static std::string |
pd_styler.h:149 |
|
|
std::vector<std::map<std::string, std::string>> |
pd_styler.h:502 |
|
|
Styler& |
pd_styler.h:370 |
|
|
Styler& |
pd_styler.h:380 |
|
|
Styler& |
pd_styler.h:481 |
|
|
Styler& |
pd_styler.h:260 |
|
|
Styler& |
pd_styler.h:229 |
|
|
Styler& |
pd_styler.h:243 |
|
|
Styler& |
pd_styler.h:216 |
|
|
Styler& |
pd_styler.h:280 |
|
|
static std::tuple<int, int, int> |
pd_styler.h:157 |
|
|
std::string |
pd_styler.h:658 |
|
|
std::pair<std::vector<size_t>, std::vector<size_t>> |
pd_styler.h:133 |
|
|
static std::string |
pd_styler.h:160 |
|
|
Styler& |
pd_styler.h:434 |
|
|
Styler& |
pd_styler.h:396 |
|
|
Styler& |
pd_styler.h:464 |
|
|
Styler& |
pd_styler.h:418 |
|
|
Styler& |
pd_styler.h:407 |
|
|
Styler& |
pd_styler.h:426 |
|
|
Styler& |
pd_styler.h:444 |
|
|
Styler& |
pd_styler.h:454 |
|
|
Styler& |
pd_styler.h:319 |
|
|
Styler& |
pd_styler.h:510 |
Code Examples#
The following examples are extracted from the test suite.
apply (pd_test_1_all.cpp:11244)
11234 void pd_test_func_apply_dataframe_apply_axis0() {
11235 std::cout << "========= DataFrame apply axis=0 ======================";
11236
11237 std::map<std::string, std::vector<double>> data = {
11238 {"A", {1.0, 2.0, 3.0}},
11239 {"B", {4.0, 5.0, 6.0}}
11240 };
11241 pandas::DataFrame df(data);
11242
11243 // apply axis=0 applies function to each column
11244 auto result = df.apply([](const std::vector<double>& col) {
11245 return std::accumulate(col.begin(), col.end(), 0.0);
11246 }, 0);
11247
11248 bool passed = true;
11249
11250 // Plan F·dtype: axis=0 reduce now returns a single "result" column
11251 // with the original column names ("A", "B") as the row index.
11252 // Sum of A: 1+2+3=6, Sum of B: 4+5+6=15
11253 const auto& result_col = result["result"];
11254 double sum_a = std::stod(result_col.get_value_str(0));
map (pd_test_1_all.cpp:5839)
5829// Map Tests
5830// ============================================================================
5831
5832void pd_test_categorical_index_map() {
5833 std::cout << "========= map =========================================";
5834
5835 pandas::CategoricalArray arr({"yes", "no", "yes"});
5836 pandas::CategoricalIndex idx(arr);
5837
5838 std::unordered_map<std::string, std::string> mapping = {{"yes", "1"}, {"no", "0"}};
5839 pandas::CategoricalIndex mapped = idx.map(mapping);
5840
5841 bool passed = (mapped.has_category("1") && mapped.has_category("0") &&
5842 !mapped.has_category("yes") && !mapped.has_category("no"));
5843 if (!passed) {
5844 std::cout << " [FAIL] : in pd_test_categorical_index_map()" << std::endl;
5845 throw std::runtime_error("pd_test_categorical_index_map failed");
5846 }
5847
5848 std::cout << " -> tests passed" << std::endl;
5849}
pipe (pd_test_1_all.cpp:11164)
11154 // Pipe applies function to entire Series
11155 auto add_mean = [](const pandas::Series<double>& ser, double offset) {
11156 auto mean_val = ser.mean();
11157 std::vector<double> result;
11158 for (size_t i = 0; i < ser.size(); ++i) {
11159 result.push_back(ser[i] + mean_val.value_or(0.0) + offset);
11160 }
11161 return pandas::Series<double>(result, ser.name());
11162 };
11163
11164 auto result = s.pipe(add_mean, 10.0);
11165
11166 bool passed = true;
11167 // mean is 2.5, offset is 10.0, so each value + 12.5
11168 std::vector<double> expected = {13.5, 14.5, 15.5, 16.5};
11169 for (size_t i = 0; i < result.size(); ++i) {
11170 if (!approx_equal(result[i], expected[i])) {
11171 passed = false;
11172 std::cout << " [FAIL] : in pd_test_func_apply_series_pipe() : value mismatch at " << i << std::endl;
11173 throw std::runtime_error("pd_test_func_apply_series_pipe failed: value mismatch");
11174 }
concat (pd_test_1_all.cpp:17717)
17707}
17708
17709void pd_test_period_index_concat() {
17710 std::cout << "========= concat factory ==============================";
17711
17712 std::vector<int64_t> ordinals1 = {0, 1};
17713 std::vector<int64_t> ordinals2 = {2, 3};
17714 pandas::PeriodIndex idx1(ordinals1, "D");
17715 pandas::PeriodIndex idx2(ordinals2, "D");
17716
17717 pandas::PeriodIndex concatenated = pandas::PeriodIndex::concat({idx1, idx2});
17718
17719 bool passed = (concatenated.size() == 4);
17720 if (!passed) {
17721 std::cout << " [FAIL] : in pd_test_period_index_concat()" << std::endl;
17722 throw std::runtime_error("pd_test_period_index_concat failed");
17723 }
17724
17725 std::cout << " -> tests passed" << std::endl;
17726}
to_html (pd_test_1_all.cpp:13438)
13428 void pd_test_io_to_html() {
13429 std::cout << "========= to_html ================================";
13430
13431 std::map<std::string, std::vector<double>> data;
13432 data["A"] = {1.0, 2.0};
13433 data["B"] = {3.0, 4.0};
13434
13435 pandas::DataFrame df(data);
13436
13437 std::string html = df.to_html();
13438
13439 // Check for key HTML elements
13440 bool has_table = (html.find("<table") != std::string::npos);
13441 bool has_thead = (html.find("<thead>") != std::string::npos);
13442 bool has_tbody = (html.find("<tbody>") != std::string::npos);
13443 bool has_th = (html.find("<th>") != std::string::npos);
13444 bool has_td = (html.find("<td>") != std::string::npos);
13445
13446 bool passed = has_table && has_thead && has_tbody && has_th && has_td;
to_html (pd_test_1_all.cpp:13438)
13428 void pd_test_io_to_html() {
13429 std::cout << "========= to_html ================================";
13430
13431 std::map<std::string, std::vector<double>> data;
13432 data["A"] = {1.0, 2.0};
13433 data["B"] = {3.0, 4.0};
13434
13435 pandas::DataFrame df(data);
13436
13437 std::string html = df.to_html();
13438
13439 // Check for key HTML elements
13440 bool has_table = (html.find("<table") != std::string::npos);
13441 bool has_thead = (html.find("<thead>") != std::string::npos);
13442 bool has_tbody = (html.find("<tbody>") != std::string::npos);
13443 bool has_th = (html.find("<th>") != std::string::npos);
13444 bool has_td = (html.find("<td>") != std::string::npos);
13445
13446 bool passed = has_table && has_thead && has_tbody && has_th && has_td;
to_latex (pd_test_2_all.cpp:9446)
9436 void pd_test_styler_to_latex() {
9437 std::cout << "========= to_latex =================================";
9438
9439 std::map<std::string, std::vector<double>> data = {
9440 {"A", {1.0, 2.0, 3.0}},
9441 {"B", {4.0, 5.0, 6.0}}
9442 };
9443 pandas::DataFrame df(data);
9444
9445 auto styler = df.style();
9446 std::string latex = styler.to_latex();
9447
9448 if (!contains(latex, "\\begin{tabular}")) {
9449 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not produce tabular environment" << std::endl;
9450 throw std::runtime_error("pd_test_styler_to_latex failed: did not produce tabular environment");
9451 }
9452 if (!contains(latex, "\\end{tabular}")) {
9453 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not close tabular environment" << std::endl;
9454 throw std::runtime_error("pd_test_styler_to_latex failed: did not close tabular environment");
9455 }
to_latex (pd_test_2_all.cpp:9446)
9436 void pd_test_styler_to_latex() {
9437 std::cout << "========= to_latex =================================";
9438
9439 std::map<std::string, std::vector<double>> data = {
9440 {"A", {1.0, 2.0, 3.0}},
9441 {"B", {4.0, 5.0, 6.0}}
9442 };
9443 pandas::DataFrame df(data);
9444
9445 auto styler = df.style();
9446 std::string latex = styler.to_latex();
9447
9448 if (!contains(latex, "\\begin{tabular}")) {
9449 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not produce tabular environment" << std::endl;
9450 throw std::runtime_error("pd_test_styler_to_latex failed: did not produce tabular environment");
9451 }
9452 if (!contains(latex, "\\end{tabular}")) {
9453 std::cout << " [FAIL] : in pd_test_styler_to_latex() : did not close tabular environment" << std::endl;
9454 throw std::runtime_error("pd_test_styler_to_latex failed: did not close tabular environment");
9455 }
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
to_string (pd_test_1_all.cpp:2693)
2683 pandas::PeriodArray arr_m(std::vector<std::string>{
2684 "2020-01",
2685 "NaT",
2686 "2025-06"
2687 }, "M");
2688
2689 // Year
2690 auto years = arr_m.year();
2691 auto y0 = years[0];
2692 if (!y0.has_value() || y0.value() != 2020) {
2693 std::cout << " [FAIL] : year[0] should be 2020, got " << (y0.has_value() ? std::to_string(y0.value()) : "NA") << std::endl;
2694 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[0]");
2695 }
2696
2697 auto y1 = years[1];
2698 if (y1.has_value()) {
2699 std::cout << " [FAIL] : year[1] should be NA (NaT)" << std::endl;
2700 throw std::runtime_error("pd_test_period_array_year_month_quarter failed: year[1] should be NA");
2701 }
2702
2703 auto y2 = years[2];
background_gradient (pd_test_2_all.cpp:9286)
9276 void pd_test_styler_background_gradient() {
9277 std::cout << "========= background_gradient ======================";
9278
9279 std::map<std::string, std::vector<double>> data = {
9280 {"A", {1.0, 2.0, 3.0, 4.0, 5.0}},
9281 {"B", {10.0, 20.0, 30.0, 40.0, 50.0}}
9282 };
9283 pandas::DataFrame df(data);
9284
9285 auto styler = df.style().background_gradient();
9286 std::string html = styler.to_html();
9287
9288 if (!contains(html, "background-color: #")) {
9289 std::cout << " [FAIL] : in pd_test_styler_background_gradient() : did not apply color styles" << std::endl;
9290 throw std::runtime_error("pd_test_styler_background_gradient failed: did not apply color styles");
9291 }
9292
9293 auto styler2 = df.style().background_gradient("Reds");
9294 std::string html2 = styler2.to_html();
bar (pd_test_2_all.cpp:9332)
9322 }
9323
9324 void pd_test_styler_bar() {
9325 std::cout << "========= bar ======================================";
9326
9327 std::map<std::string, std::vector<double>> data = {
9328 {"A", {10.0, 30.0, 50.0, 70.0, 100.0}}
9329 };
9330 pandas::DataFrame df(data);
9331
9332 auto styler = df.style().bar();
9333 std::string html = styler.to_html();
9334
9335 if (!contains(html, "linear-gradient")) {
9336 std::cout << " [FAIL] : in pd_test_styler_bar() : did not apply gradient background" << std::endl;
9337 throw std::runtime_error("pd_test_styler_bar failed: did not apply gradient background");
9338 }
9339
9340 std::cout << " -> tests passed" << std::endl;
9341 }
clear (pd_test_1_all.cpp:16341)
16331 }
16332
16333 // Test has_type
16334 passed = attrs.has_type<std::string>("author") && !attrs.has_type<int>("author");
16335 if (!passed) {
16336 std::cout << " [FAIL] : in pd_test_ndframe_attrs() : has_type" << std::endl;
16337 throw std::runtime_error("pd_test_ndframe_attrs failed: has_type");
16338 }
16339
16340 // Test clear
16341 attrs.clear();
16342 passed = attrs.empty();
16343 if (!passed) {
16344 std::cout << " [FAIL] : in pd_test_ndframe_attrs() : clear" << std::endl;
16345 throw std::runtime_error("pd_test_ndframe_attrs failed: clear");
16346 }
16347
16348 std::cout << " -> tests passed" << std::endl;
16349 }
16350
16351 // =====================================================================
data (pd_test_1_all.cpp:9114)
9104 throw std::runtime_error("pd_test_datetime_mixin_default_constructor failed");
9105 }
9106
9107 std::cout << " -> tests passed" << std::endl;
9108}
9109
9110void pd_test_datetime_mixin_array_constructor() {
9111 std::cout << "========= DatetimeTDMixin array constructor =========================";
9112
9113 // Create DatetimeArray with some values
9114 numpy::NDArray<numpy::datetime64> data(std::vector<size_t>{3});
9115 data.setElementAt({0}, numpy::datetime64(1000000000000000000LL, numpy::DateTimeUnit::Nanosecond)); // ~2001
9116 data.setElementAt({1}, numpy::datetime64(1500000000000000000LL, numpy::DateTimeUnit::Nanosecond)); // ~2017
9117 data.setElementAt({2}, numpy::datetime64(1600000000000000000LL, numpy::DateTimeUnit::Nanosecond)); // ~2020
9118
9119 numpy::NDArray<numpy::bool_> mask(std::vector<size_t>{3});
9120 mask.setElementAt({0}, numpy::bool_(false));
9121 mask.setElementAt({1}, numpy::bool_(false));
9122 mask.setElementAt({2}, numpy::bool_(false));
9123
9124 pandas::DatetimeArray arr(data, mask);
format (main.cpp:20)
10int main() {
11 // Automatically log all output to temp/pd_test_output.log
12 numpy::TestLogger logger("temp/pd_test_output.log");
13
14 int res = 0;
15 int res1 = 0;
16 std::string resS = "";
17
18 // call all the tests
19 res1 = dataframe_tests::pd_test_main();
20 resS += std::format(" pd_test_main: {} errors\n", res1);
21 res += res1;
22
23 std::cout << "\n------------------------- main --------------------------------------------\n";
24 std::cout << std::endl << "All tests completed. Nb errors = " << res << std::endl;
25 std::cout << "Details: \n" << resS;
26 std::cout << "\n---------------------------------------------------------------------------\n";
27 return res;
28}
format (main.cpp:20)
10int main() {
11 // Automatically log all output to temp/pd_test_output.log
12 numpy::TestLogger logger("temp/pd_test_output.log");
13
14 int res = 0;
15 int res1 = 0;
16 std::string resS = "";
17
18 // call all the tests
19 res1 = dataframe_tests::pd_test_main();
20 resS += std::format(" pd_test_main: {} errors\n", res1);
21 res += res1;
22
23 std::cout << "\n------------------------- main --------------------------------------------\n";
24 std::cout << std::endl << "All tests completed. Nb errors = " << res << std::endl;
25 std::cout << "Details: \n" << resS;
26 std::cout << "\n---------------------------------------------------------------------------\n";
27 return res;
28}
hide (pd_test_2_all.cpp:9420)
9410 std::cout << "========= hide =====================================";
9411
9412 std::map<std::string, std::vector<double>> data = {
9413 {"A", {1.0, 2.0, 3.0}},
9414 {"B", {4.0, 5.0, 6.0}},
9415 {"C", {7.0, 8.0, 9.0}}
9416 };
9417 pandas::DataFrame df(data);
9418
9419 pandas::StyleSubset subset({"B"});
9420 auto styler = df.style().hide(subset, 0);
9421 std::string html = styler.to_html();
9422
9423 if (contains(html, "<th>B</th>")) {
9424 std::cout << " [FAIL] : in pd_test_styler_hide() : did not hide column B" << std::endl;
9425 throw std::runtime_error("pd_test_styler_hide failed: did not hide column B");
9426 }
9427
9428 if (!contains(html, "<th>A</th>") || !contains(html, "<th>C</th>")) {
9429 std::cout << " [FAIL] : in pd_test_styler_hide() : removed wrong columns" << std::endl;
9430 throw std::runtime_error("pd_test_styler_hide failed: removed wrong columns");
highlight_between (pd_test_2_all.cpp:9266)
9256 void pd_test_styler_highlight_between() {
9257 std::cout << "========= highlight_between ========================";
9258
9259 std::map<std::string, std::vector<double>> data = {
9260 {"A", {1.0, 5.0, 10.0}},
9261 {"B", {2.0, 6.0, 8.0}}
9262 };
9263 pandas::DataFrame df(data);
9264
9265 auto styler = df.style().highlight_between({}, "lightblue", std::nullopt, 3.0, 7.0);
9266 std::string html = styler.to_html();
9267
9268 if (!contains(html, "background-color: lightblue")) {
9269 std::cout << " [FAIL] : in pd_test_styler_highlight_between() : did not apply lightblue background" << std::endl;
9270 throw std::runtime_error("pd_test_styler_highlight_between failed: did not apply lightblue background");
9271 }
9272
9273 std::cout << " -> tests passed" << std::endl;
9274 }
highlight_max (pd_test_2_all.cpp:9188)
9178 void pd_test_styler_highlight_max() {
9179 std::cout << "========= highlight_max ============================";
9180
9181 std::map<std::string, std::vector<double>> data = {
9182 {"A", {1.0, 3.0, 2.0}},
9183 {"B", {4.0, 5.0, 6.0}}
9184 };
9185 pandas::DataFrame df(data);
9186
9187 // Highlight max with default color (yellow)
9188 auto styler = df.style().highlight_max();
9189 std::string html = styler.to_html();
9190
9191 if (!contains(html, "background-color: yellow")) {
9192 std::cout << " [FAIL] : in pd_test_styler_highlight_max() : did not apply yellow background" << std::endl;
9193 throw std::runtime_error("pd_test_styler_highlight_max failed: did not apply yellow background");
9194 }
9195
9196 // Test with custom color
9197 auto styler2 = df.style().highlight_max({}, "lightgreen");
9198 std::string html2 = styler2.to_html();
highlight_min (pd_test_2_all.cpp:9217)
9207 void pd_test_styler_highlight_min() {
9208 std::cout << "========= highlight_min ============================";
9209
9210 std::map<std::string, std::vector<double>> data = {
9211 {"A", {1.0, 3.0, 2.0}},
9212 {"B", {4.0, 5.0, 6.0}}
9213 };
9214 pandas::DataFrame df(data);
9215
9216 auto styler = df.style().highlight_min();
9217 std::string html = styler.to_html();
9218
9219 if (!contains(html, "background-color: yellow")) {
9220 std::cout << " [FAIL] : in pd_test_styler_highlight_min() : did not apply yellow background" << std::endl;
9221 throw std::runtime_error("pd_test_styler_highlight_min failed: did not apply yellow background");
9222 }
9223
9224 std::cout << " -> tests passed" << std::endl;
9225 }
highlight_null (pd_test_2_all.cpp:9237)
9227 void pd_test_styler_highlight_null() {
9228 std::cout << "========= highlight_null ===========================";
9229
9230 std::map<std::string, std::vector<std::string>> data = {
9231 {"A", {"1.0", "NaN", "3.0"}},
9232 {"B", {"4.0", "5.0", "NA"}}
9233 };
9234 pandas::DataFrame df(data);
9235
9236 auto styler = df.style().highlight_null();
9237 std::string html = styler.to_html();
9238
9239 if (!contains(html, "background-color: red")) {
9240 std::cout << " [FAIL] : in pd_test_styler_highlight_null() : did not apply red background" << std::endl;
9241 throw std::runtime_error("pd_test_styler_highlight_null failed: did not apply red background");
9242 }
9243
9244 // Test with custom color
9245 auto styler2 = df.style().highlight_null("orange");
9246 std::string html2 = styler2.to_html();
highlight_quantile (pd_test_2_all.cpp:9672)
9662 }
9663
9664 void pd_test_styler_highlight_quantile() {
9665 std::cout << "========= highlight_quantile =======================";
9666
9667 std::map<std::string, std::vector<double>> data = {
9668 {"A", {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}}
9669 };
9670 pandas::DataFrame df(data);
9671
9672 auto styler = df.style().highlight_quantile({}, "lightgreen", 0, 0.8, 1.0);
9673 std::string html = styler.to_html();
9674
9675 if (!contains(html, "background-color: lightgreen")) {
9676 std::cout << " [FAIL] : in pd_test_styler_highlight_quantile() : did not apply highlight" << std::endl;
9677 throw std::runtime_error("pd_test_styler_highlight_quantile failed: did not apply highlight");
9678 }
9679
9680 std::cout << " -> tests passed" << std::endl;
9681 }
render (pd_test_2_all.cpp:9161)
9151 std::map<std::string, std::vector<double>> data = {
9152 {"A", {1.0, 2.0, 3.0}},
9153 {"B", {4.0, 5.0, 6.0}}
9154 };
9155 pandas::DataFrame df(data);
9156
9157 // Get Styler
9158 auto styler = df.style();
9159
9160 // Check that render produces HTML
9161 std::string html = styler.render();
9162 if (!contains(html, "<table>")) {
9163 std::cout << " [FAIL] : in pd_test_styler_basic() : render() did not produce table tag" << std::endl;
9164 throw std::runtime_error("pd_test_styler_basic failed: render() did not produce table tag");
9165 }
9166 if (!contains(html, "<th>A</th>")) {
9167 std::cout << " [FAIL] : in pd_test_styler_basic() : render() did not include column header A" << std::endl;
9168 throw std::runtime_error("pd_test_styler_basic failed: render() did not include column header A");
9169 }
9170 if (!contains(html, "<th>B</th>")) {
9171 std::cout << " [FAIL] : in pd_test_styler_basic() : render() did not include column header B" << std::endl;
set_caption (pd_test_2_all.cpp:9370)
9360 }
9361
9362 void pd_test_styler_set_caption() {
9363 std::cout << "========= set_caption ==============================";
9364
9365 std::map<std::string, std::vector<double>> data = {
9366 {"A", {1.0, 2.0, 3.0}}
9367 };
9368 pandas::DataFrame df(data);
9369
9370 auto styler = df.style().set_caption("My Data Table");
9371 std::string html = styler.to_html();
9372
9373 if (!contains(html, "<caption>My Data Table</caption>")) {
9374 std::cout << " [FAIL] : in pd_test_styler_set_caption() : did not add caption element" << std::endl;
9375 throw std::runtime_error("pd_test_styler_set_caption failed: did not add caption element");
9376 }
9377
9378 std::cout << " -> tests passed" << std::endl;
9379 }
set_properties (pd_test_2_all.cpp:9394)
9384 std::map<std::string, std::vector<double>> data = {
9385 {"A", {1.0, 2.0}},
9386 {"B", {3.0, 4.0}}
9387 };
9388 pandas::DataFrame df(data);
9389
9390 std::map<std::string, std::string> props = {
9391 {"font-weight", "bold"},
9392 {"text-align", "center"}
9393 };
9394 auto styler = df.style().set_properties(props);
9395 std::string html = styler.to_html();
9396
9397 if (!contains(html, "font-weight: bold")) {
9398 std::cout << " [FAIL] : in pd_test_styler_set_properties() : did not apply font-weight" << std::endl;
9399 throw std::runtime_error("pd_test_styler_set_properties failed: did not apply font-weight");
9400 }
9401 if (!contains(html, "text-align: center")) {
9402 std::cout << " [FAIL] : in pd_test_styler_set_properties() : did not apply text-align" << std::endl;
9403 throw std::runtime_error("pd_test_styler_set_properties failed: did not apply text-align");
9404 }
set_table_styles (pd_test_2_all.cpp:9696)
9686 std::map<std::string, std::vector<double>> data = {
9687 {"A", {1.0, 2.0, 3.0}}
9688 };
9689 pandas::DataFrame df(data);
9690
9691 std::vector<std::pair<std::string, std::string>> styles = {
9692 {"th", "background-color: lightgray;"},
9693 {"td", "padding: 10px;"}
9694 };
9695
9696 auto styler = df.style().set_table_styles(styles);
9697 std::string html = styler.to_html();
9698
9699 if (!contains(html, "<style type=\"text/css\">")) {
9700 std::cout << " [FAIL] : in pd_test_styler_set_table_styles() : did not add style block" << std::endl;
9701 throw std::runtime_error("pd_test_styler_set_table_styles failed: did not add style block");
9702 }
9703 if (!contains(html, "th { background-color: lightgray; }")) {
9704 std::cout << " [FAIL] : in pd_test_styler_set_table_styles() : did not include th style" << std::endl;
9705 throw std::runtime_error("pd_test_styler_set_table_styles failed: did not include th style");
9706 }
set_uuid (pd_test_2_all.cpp:9653)
9643 }
9644
9645 void pd_test_styler_set_uuid() {
9646 std::cout << "========= set_uuid =================================";
9647
9648 std::map<std::string, std::vector<double>> data = {
9649 {"A", {1.0, 2.0, 3.0}}
9650 };
9651 pandas::DataFrame df(data);
9652
9653 auto styler = df.style().set_uuid("my-custom-table-id");
9654 std::string html = styler.to_html();
9655
9656 if (!contains(html, "id=\"my-custom-table-id\"")) {
9657 std::cout << " [FAIL] : in pd_test_styler_set_uuid() : did not set table id" << std::endl;
9658 throw std::runtime_error("pd_test_styler_set_uuid failed: did not set table id");
9659 }
9660
9661 std::cout << " -> tests passed" << std::endl;
9662 }
text_gradient (pd_test_2_all.cpp:9313)
9303 }
9304
9305 void pd_test_styler_text_gradient() {
9306 std::cout << "========= text_gradient ============================";
9307
9308 std::map<std::string, std::vector<double>> data = {
9309 {"A", {1.0, 2.0, 3.0}}
9310 };
9311 pandas::DataFrame df(data);
9312
9313 auto styler = df.style().text_gradient("Blues");
9314 std::string html = styler.to_html();
9315
9316 if (!contains(html, "color: #")) {
9317 std::cout << " [FAIL] : in pd_test_styler_text_gradient() : did not apply text color styles" << std::endl;
9318 throw std::runtime_error("pd_test_styler_text_gradient failed: did not apply text color styles");
9319 }
9320
9321 std::cout << " -> tests passed" << std::endl;
9322 }