DataFrameEWM#
-
class pandas::DataFrameEWM#
Window operation class for rolling/expanding calculations.
Example#
#include <pandas/pandas.h>
using namespace pandas;
// Use DataFrameEWM
DataFrameEWM obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
pd_dataframe.h:12801 |
Statistics#
Aggregation#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
pd_dataframe.h:12875 |
|
|
DataFrame |
pd_dataframe.h:12849 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
bool |
pd_dataframe.h:12843 |
|
|
const DataFrame& |
pd_dataframe.h:12845 |
|
|
bool |
pd_dataframe.h:12844 |
|
|
void |
pd_dataframe.h:12804 |
|
|
void |
pd_dataframe.h:12810 |
|
|
double |
pd_dataframe.h:12842 |
Code Examples#
The following examples are extracted from the test suite.
mean (pd_test_1_all.cpp:282)
272 std::optional<bool>(true),
273 std::optional<bool>(true)
274 });
275
276 auto s = arr.sum();
277 if (!s.has_value() || s.value() != 3) {
278 std::cout << " [FAIL] : in pd_test_boolean_array_reductions() : sum should be 3" << std::endl;
279 throw std::runtime_error("pd_test_boolean_array_reductions failed: sum");
280 }
281
282 auto m = arr.mean();
283 if (!m.has_value() || std::abs(m.value() - 0.75) > 0.001) {
284 std::cout << " [FAIL] : in pd_test_boolean_array_reductions() : mean should be 0.75" << std::endl;
285 throw std::runtime_error("pd_test_boolean_array_reductions failed: mean");
286 }
287
288 std::cout << " -> tests passed" << std::endl;
289 }
290
291 void pd_test_boolean_array_dtype() {
292 std::cout << "========= BooleanArray: dtype ======================= ";
std (pd_test_1_all.cpp:4526)
4516#include "../pandas/pd_series.h"
4517
4518namespace dataframe_tests {
4519 namespace dataframe_tests_aggregation {
4520
4521 void pd_test_aggregation_series_sem() {
4522 std::cout << "========= Series sem ============================";
4523
4524 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
4525 auto sem_val = s.sem();
4526 // std(ddof=1) = sqrt(2.5), sem = sqrt(2.5)/sqrt(5) ≈ 0.707
4527 bool passed = sem_val.has_value() && std::abs(*sem_val - 0.707) < 0.01;
4528 if (!passed) {
4529 std::cout << " [FAIL] : in pd_test_aggregation_series_sem() : sem value incorrect" << std::endl;
4530 throw std::runtime_error("pd_test_aggregation_series_sem failed: sem value incorrect");
4531 }
4532
4533 std::cout << " -> tests passed" << std::endl;
4534 }
4535
4536 void pd_test_aggregation_series_quantile() {
var (pd_test_1_all.cpp:20890)
20880 throw std::runtime_error("pd_test_expanding_std failed: expanding std values incorrect");
20881 }
20882
20883 std::cout << " -> tests passed" << std::endl;
20884 }
20885
20886 void pd_test_expanding_var() {
20887 std::cout << "========= Expanding var =========================";
20888
20889 pandas::Series<double> s({1.0, 2.0, 3.0, 4.0, 5.0});
20890 auto result = s.expanding().var();
20891
20892 // Expanding var (ddof=1): NaN, 0.5, 1.0, 1.6667, 2.5
20893 bool passed = std::isnan(result[0]) &&
20894 std::abs(result[1] - 0.5) < 0.001 &&
20895 std::abs(result[2] - 1.0) < 0.001 &&
20896 std::abs(result[3] - 1.6667) < 0.001 &&
20897 std::abs(result[4] - 2.5) < 0.001;
20898 if (!passed) {
20899 std::cout << " [FAIL] : in pd_test_expanding_var() : expanding var values incorrect" << std::endl;
20900 throw std::runtime_error("pd_test_expanding_var failed: expanding var values incorrect");
dataframe (pd_test_2_all.cpp:11742)
11732 std::cout << " [FAIL] : wrong dimensions" << std::endl;
11733 std::remove(temp_path.c_str());
11734 throw std::runtime_error("pd_test_to_hdf_mixed_types failed");
11735 }
11736
11737 std::remove(temp_path.c_str());
11738 std::cout << " -> tests passed" << std::endl;
11739 }
11740
11741 void pd_test_to_hdf_empty_dataframe() {
11742 std::cout << "========= to_hdf empty dataframe (real HDF5) ===================";
11743
11744 pandas::DataFrame df;
11745 std::string temp_path = "temp/test_hdf5_empty.h5";
11746 df.to_hdf(temp_path, "df", "w");
11747
11748 // Just verify file was created
11749 std::ifstream file(temp_path);
11750 if (!file.is_open()) {
11751 std::cout << " [FAIL] : file not created" << std::endl;
11752 throw std::runtime_error("pd_test_to_hdf_empty_dataframe failed");
span (pd_test_5_all.cpp:57296)
57286 f_test_astype_reindex_chain_coverage_23_main_ns::f_test_astype_reindex_chain_coverage_23_main();
57287}
57288
57289
57290// --- f_test_format_helpers_coverage_9.cpp ---
57291namespace f_test_format_helpers_coverage_9_main_ns {
57292
57293static void f_format_helpers_coverage_8b2f47_case_A01_empty_span_returns_min(int& local_fail) {
57294 std::cout << "-- case_A01_empty_span_returns_min\n";
57295 std::vector<double> v;
57296 int p = pandas::detail::infer_float_repr_precision(std::span<const double>(v));
57297 pandas_tests::check(p == 1,
57298 "format_helpers_coverage_8b2f47_case_A01.empty_returns_min1", local_fail);
57299}
57300
57301static void f_format_helpers_coverage_8b2f47_case_A02_all_integer_returns_min(int& local_fail) {
57302 std::cout << "-- case_A02_all_integer_returns_min\n";
57303 std::vector<double> v = {1.0, 2.0, 3.0};
57304 int p = pandas::detail::infer_float_repr_precision(std::span<const double>(v));
57305 pandas_tests::check(p == 1,
57306 "format_helpers_coverage_8b2f47_case_A02.all_integer_returns_min1", local_fail);