DataFrameResampler#
-
class numpy::DataFrameResampler#
numpy C++ class.
Example#
#include <numpy/np_ndarray.h>
using namespace numpy;
// Use DataFrameResampler
DataFrameResampler obj;
// ... operations ...
Constructors#
Signature |
Location |
Example |
|---|---|---|
|
df_resampler.h:106 |
Indexing / Selection#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
std::vector<std::string> |
df_resampler.h:179 |
|
|
int64_t |
df_resampler.h:177 |
Statistics#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_resampler.h:118 |
|
|
DataFrame |
df_resampler.h:116 |
|
|
DataFrame |
df_resampler.h:122 |
|
|
DataFrame |
df_resampler.h:117 |
|
|
DataFrame |
df_resampler.h:119 |
|
|
DataFrame |
df_resampler.h:115 |
|
|
DataFrame |
df_resampler.h:120 |
Other Methods#
Signature |
Return Type |
Location |
Example |
|---|---|---|---|
|
DataFrame |
df_resampler.h:128 |
|
|
DataFrame |
df_resampler.h:134 |
|
|
std::vector<double> |
df_resampler.h:182 |
|
|
DataFrame |
df_resampler.h:160 |
|
|
void |
df_resampler.h:176 |
|
|
static double |
df_resampler.h:185 |
|
|
DataFrame |
df_resampler.h:121 |
|
|
DataFrame |
df_resampler.h:157 |
|
|
DataFrame |
df_resampler.h:141 |
|
|
const std::string& |
df_resampler.h:173 |
|
|
DataFrame |
df_resampler.h:144 |
|
|
size_t |
df_resampler.h:170 |
|
|
DataFrame |
df_resampler.h:150 |
|
|
int64_t |
df_resampler.h:178 |
|
|
DataFrame |
df_resampler.h:167 |
Code Examples#
The following examples are extracted from the test suite.
max (np_test_1_all.cpp:7274)
7264 if (sizeof(uintp) == sizeof(void*)) {
7265 // std::cout << " -> uintp size matches pointer size";
7266 } else {
7267 // std::cout << " ✗ uintp size doesn't match pointer size" << std::endl;
7268 }
7269
7270 // Test range limits
7271 // std::cout << "Range Information:" << std::endl;
7272 // std::cout << " intp min: " << std::numeric_limits<intp>::min() << std::endl;
7273 // std::cout << " intp max: " << std::numeric_limits<intp>::max() << std::endl;
7274 // std::cout << " uintp max: " << std::numeric_limits<uintp>::max() << std::endl;
7275 // std::cout << " longdouble digits: " << std::numeric_limits<longdouble>::digits << std::endl;
7276
7277 std::cout << " -> tests passed" << std::endl;
7278}
7279
7280void testComplexArithmeticExtendedTypes() {
7281 std::cout << "========= testComplexArithmeticExtendedTypes =======================";
7282
7283 clongdouble c1(3.0L, 4.0L); // 3 + 4i
mean (np_test_1_all.cpp:11714)
11704 // Create test array
11705 auto array = createInt32Array({ 2, 3 }, 0);
11706 array.setElementAt({ 0, 0 }, 1);
11707 array.setElementAt({ 0, 1 }, 2);
11708 array.setElementAt({ 0, 2 }, 3);
11709 array.setElementAt({ 1, 0 }, 4);
11710 array.setElementAt({ 1, 1 }, 5);
11711 array.setElementAt({ 1, 2 }, 6);
11712
11713 // Test mean without axis
11714 auto mean_all = mean(array);
11715 if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) {
11716 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))";
11717 std::cout << std::string("[FAIL] ") + description << std::endl;
11718 throw std::runtime_error(description);
11719 }
11720 // std::cout << "[OK] mean (all elements) works correctly\n";
11721
11722 // Test mean along axis 0
11723 auto mean_axis0 = mean(array, 0);
11724 if (!(mean_axis0.getShape()[0] == 3)) {
median (np_test_1_all.cpp:11882)
11872 std::cout << "========= testMedianAndPercentiles =======================";
11873
11874 // Test median with odd number of elements
11875 auto odd_array = createInt32Array({ 5 }, 0);
11876 odd_array.setElementAt({ 0 }, 1);
11877 odd_array.setElementAt({ 1 }, 3);
11878 odd_array.setElementAt({ 2 }, 5);
11879 odd_array.setElementAt({ 3 }, 7);
11880 odd_array.setElementAt({ 4 }, 9);
11881
11882 auto median_odd = median(odd_array);
11883 if (!(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))) {
11884 std::string description = std::string("testMedianAndPercentiles():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(median_odd.getElementAt({ 0 }), 5.0, 1e-10))";
11885 std::cout << std::string("[FAIL] ") + description << std::endl;
11886 throw std::runtime_error(description);
11887 }
11888 // std::cout << "[OK] Median with odd count works correctly\n";
11889
11890 // Test median with even number of elements
11891 auto even_array = createInt32Array({ 4 }, 0);
11892 even_array.setElementAt({ 0 }, 1);
min (np_test_1_all.cpp:2350)
2340 if (i % 3 == 0) {
2341 large_array.setElementAt({i}, object_(static_cast<int>(i)));
2342 } else if (i % 3 == 1) {
2343 large_array.setElementAt({i}, object_(static_cast<double>(i) * 0.5));
2344 } else {
2345 large_array.setElementAt({i}, object_(std::string("str") + std::to_string(i)));
2346 }
2347 }
2348
2349 // Verify pattern
2350 for (size_t i = 0; i < std::min(large_size, size_t(100)); ++i) { // Check first 100
2351 object_ obj = large_array.getElementAt({i});
2352 if (i % 3 == 0) {
2353 if (!(obj.is_type<int>())) {
2354 std::string description = std::string("testArrayEdgeCases():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<int>())";
2355 std::cout << std::string("[FAIL] ") + description << std::endl;
2356 throw std::runtime_error(description);
2357 }
2358 } else if (i % 3 == 1) {
2359 if (!(obj.is_type<double>())) {
2360 std::string description = std::string("unknown_function():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(obj.is_type<double>())";
sum (np_test_1_all.cpp:11766)
11756 throw std::runtime_error(description);
11757 }
11758 if (!(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))) {
11759 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_axis1.getElementAt({ 1 }), 5.0, 1e-10))";
11760 std::cout << std::string("[FAIL] ") + description << std::endl;
11761 throw std::runtime_error(description);
11762 }
11763 // std::cout << "[OK] mean along axis 1 works correctly\n";
11764
11765 // Test sum
11766 auto sum_all = sum(array);
11767 if (!(sum_all.getElementAt({ 0 }) == 21)) {
11768 std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(sum_all.getElementAt({ 0 }) == 21)";
11769 std::cout << std::string("[FAIL] ") + description << std::endl;
11770 throw std::runtime_error(description);
11771 }
11772 // std::cout << "[OK] sum works correctly\n";
11773
11774 // Test min and max
11775 auto min_all = min(array);
11776 auto max_all = max(array);
var (np_test_1_all.cpp:11816)
11806 std::cout << "========= testVarianceAndStandardDeviation =======================";
11807
11808 // Create test array with known variance
11809 auto array = createFloat64Array({ 4 }, 0);
11810 array.setElementAt({ 0 }, 1.0);
11811 array.setElementAt({ 1 }, 2.0);
11812 array.setElementAt({ 2 }, 3.0);
11813 array.setElementAt({ 3 }, 4.0);
11814
11815 // Test variance (population)
11816 auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance
11817 double expected_var = 1.25; // Known variance for [1,2,3,4]
11818 if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) {
11819 std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))";
11820 std::cout << std::string("[FAIL] ") + description << std::endl;
11821 throw std::runtime_error(description);
11822 }
11823 // std::cout << "[OK] Population variance works correctly\n";
11824
11825 // Test variance (sample)
11826 auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance
count (np_test_1_all.cpp:3616)
3606 // Create larger arrays for performance testing
3607 auto large_arr = NDArray<double>::createOnes({100, 100});
3608 auto broadcast_arr = NDArray<double>::createOnes({1, 100});
3609
3610 // Time the operation (basic timing)
3611 auto start = std::chrono::high_resolution_clock::now();
3612 auto result = large_arr.addArrays(broadcast_arr);
3613 auto end = std::chrono::high_resolution_clock::now();
3614
3615 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
3616 // std::cout << "Large array broadcasting took " << duration.count() << " microseconds" << std::endl;
3617
3618 // Verify result shape
3619 if (!((result.getShape() == std::vector<size_t>{100, 100}))) {
3620 std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !((result.getShape() == std::vector<size_t>{100, 100}))";
3621 std::cout << std::string("[FAIL] ") + description << std::endl;
3622 throw std::runtime_error(description);
3623 }
3624 if (!(result.getElementAt({50, 50}) == 2.0)) {
3625 std::string description = std::string("test_broadcasting_performance():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(result.getElementAt({50, 50}) == 2.0)";
3626 std::cout << std::string("[FAIL] ") + description << std::endl;
first (np_test_4_all.cpp:12410)
12400 // std::cout << "[OK] NaN-ignoring behavior tests\n";
12401}
12402
12403// Test both NaN returns first NaN
12404void test_fmax_both_nan() {
12405 std::cout << "========= test_fmax_both_nan ====";
12406
12407 double nan1 = std::numeric_limits<double>::quiet_NaN();
12408 double nan2 = std::numeric_limits<double>::quiet_NaN();
12409
12410 // If both are NaN, return first (which is still NaN)
12411 double result = numpy::fmax(nan1, nan2);
12412 if (!std::isnan(result)) {
12413 std::cout << " [FAIL] : test_fmax_both_nan failed - fmax(NaN, NaN) should be NaN";
12414 throw std::runtime_error("fmax(NaN, NaN) should return NaN");
12415 }
12416
12417 // std::cout << "[OK] Both NaN returns NaN test\n";
12418}
12419
12420// Test type preservation
size (np_test_1_all.cpp:47)
37using namespace numpy;
38using namespace numpy::benchmark;
39using namespace numpy::char_;
40
41// Helper functions for array comparison tests
42namespace {
43 const double TOLERANCE = 1e-10;
44
45 bool allTrue(const NDArray<bool>& arr) {
46 std::vector<size_t> indices(arr.getShape().size(), 0);
47 do {
48 if (!arr.getElementAt(indices)) {
49 return false;
50 }
51 } while (incrementIndices(indices, arr.getShape()));
52 return true;
53 }
54
55 bool allFalse(const NDArray<bool>& arr) {
56 std::vector<size_t> indices(arr.getShape().size(), 0);