hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.38k stars 298 forks source link

MedianVisitor giving wrong result #267

Closed smangano closed 8 months ago

smangano commented 8 months ago
TEST(mpo_helpers, df_median_bug)
{
  std::vector<std::string> syms =
    {
      "AAPL", "IBM",  "TSLA"
    } ;
  std::vector<double> c1 =
    {
      1.0, 2.0,  3.0
    } ;

  std::vector<double> c2 =
    {
      0.01, 0.02,  0.03,
    } ;

  std::vector<double> c3 =
    {
      0.0, NAN,  0.1
    } ;

  TestDF testDF ;
  testDF.load_data(
      std::move(syms),
      std::make_pair("c1",  c1),
      std::make_pair("c2",  c2),
      std::make_pair("c3",  c3)
    ) ;

   MedianVisitor<double>   med_visit;
   double   result = testDF.single_act_visit<double>("c1", med_visit).get_result();
   EXPECT_EQ(2.0, result) ;
   result = testDF.single_act_visit<double>("c2", med_visit).get_result();
   EXPECT_EQ(0.2, result) ;
   result = testDF.single_act_visit<double>("c3", med_visit).get_result();
   EXPECT_EQ(0.05, result) ;
}

$ ./build/test --gtest_filter=mpo_helpers.df_median_bug Note: Google Test filter = mpo_helpers.df_median_bug [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from mpo_helpers [ RUN ] mpo_helpers.df_median_bug test/test_mpo_helpers.cpp:169: Failure Expected equality of these values: 2.0 Which is: 2 result Which is: 1 test/test_mpo_helpers.cpp:171: Failure Expected equality of these values: 0.2 result Which is: 0.01 test/test_mpo_helpers.cpp:173: Failure Expected equality of these values: 0.05 result Which is: 0 [ FAILED ] mpo_helpers.df_median_bug (0 ms) [----------] 1 test from mpo_helpers (0 ms total)

[----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (0 ms total) [ PASSED ] 0 tests. [ FAILED ] 1 test, listed below: [ FAILED ] mpo_helpers.df_median_bug

1 FAILED TEST

hosseinmoein commented 8 months ago

Thanks, will take a look

hosseinmoein commented 8 months ago

@smangano , This has been fixed in master branch thx HM