Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support column rolling? #29

Closed
yssource opened this issue Jul 12, 2019 · 6 comments
Closed

Support column rolling? #29

yssource opened this issue Jul 12, 2019 · 6 comments

Comments

@yssource
Copy link
Contributor

yssource commented Jul 12, 2019

It there any a plan to support column rolling?
For instance. It would like what pandas do in the following codes.


#+begin_src python :results output
  import numpy
  import pandas

  x = numpy.array([0, 1, 2, 3, 4])
  s = pandas.Series(x)

  print(s.rolling(3).min())
  print(s.rolling(3).max())
  print(s.rolling(3).mean())
  print(s.rolling(3).std())
#+end_src

#+RESULTS:
#+begin_example
0    NaN
1    NaN
2    0.0
3    1.0
4    2.0
dtype: float64
0    NaN
1    NaN
2    2.0
3    3.0
4    4.0
dtype: float64
0    NaN
1    NaN
2    1.0
3    2.0
4    3.0
dtype: float64
0    NaN
1    NaN
2    1.0
3    1.0
4    1.0
dtype: float64
#+end_example
@hosseinmoein
Copy link
Owner

hosseinmoein commented Jul 12, 2019

@yssource
You could write a simple functor and use one of the visit() or single_act_visit() methods to get this result.
But I can add something specialized maybe in the next few days or so

@hosseinmoein
Copy link
Owner

@yssource
I implemented the SimpleRollAdptor. It works with most of the visitors.
Please see the doc and data_frame_tester.cc for usage

@yssource
Copy link
Contributor Author

It seems that the NaN is not considered.

std::vector<double> d1 = {1, 2, 3, 4, 
// 5, 
std::numeric_limits<double>::quiet_NaN(), 
6,
 // 7, 
std::numeric_limits<double>::quiet_NaN(), 
8, 9, 10, 11};
#+begin_src python :results output
  import numpy as np
  import pandas as pd

  x = np.array([0, 1, 2, 3, np.nan, 5, 6, 7, 8, np.nan, 10])
  s = pd.Series(x)

  print(s.rolling(3).min())
  print(s.rolling(3).max())
  print(s.rolling(3).mean())
  print(s.rolling(3).std())
#+end_src

#+RESULTS:
#+begin_example
0     NaN
1     NaN
2     0.0
3     1.0
4     NaN
5     NaN
6     NaN
7     5.0
8     6.0
9     NaN
10    NaN
dtype: float64
0     NaN
1     NaN
2     2.0
3     3.0
4     NaN
5     NaN
6     NaN
7     7.0
8     8.0
9     NaN
10    NaN
dtype: float64
0     NaN
1     NaN
2     1.0
3     2.0
4     NaN
5     NaN
6     NaN
7     6.0
8     7.0
9     NaN
10    NaN
dtype: float64
0     NaN
1     NaN
2     1.0
3     1.0
4     NaN
5     NaN
6     NaN
7     1.0
8     1.0
9     NaN
10    NaN
dtype: float64
#+end_example

@hosseinmoein
Copy link
Owner

That is because my generic visitors, like min, max, mean, etc., skip nans. I should make it optional.

@hosseinmoein
Copy link
Owner

@yssource
Made skipping nans optional in visitors. The default is still to skip nans.
See the tester file and docs

@yssource
Copy link
Contributor Author

It works as expected.
Thank you, so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants