Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
With the code above, the function sum_of_subtraction returns a different results if the columns of the input argument values are swapped (cf the example below).
x = np.array([[1, 2],[3, 4]])
y = x[:, [1, 0]] # columns are swapped
print(sum_of_subtraction(x)) # returns -1.0
print(sum_of_subtraction(y)) # returns 1.0
Yet, using rolling with method='table' followed with apply returns same results, no matter or the columns ordering. Even though the columns were given with a specific ordering, when calling apply with engine='numba', the columns are sorted alphabetically. With the code above, here are the results:
order_1_df:
a
b
datetime
0
-5
-5
2020-01-01 00:00:00
1
-5
-5
2020-01-02 00:00:00
2
-5
-5
2020-01-03 00:00:00
3
-3.66667
-3.66667
2020-01-04 00:00:00
4
-2.33333
-2.33333
2020-01-05 00:00:00
5
-1
-1
2020-01-06 00:00:00
order_2_df:
a
b
datetime
0
-5
-5
2020-01-01 00:00:00
1
-5
-5
2020-01-02 00:00:00
2
-5
-5
2020-01-03 00:00:00
3
-3.66667
-3.66667
2020-01-04 00:00:00
4
-2.33333
-2.33333
2020-01-05 00:00:00
5
-1
-1
2020-01-06 00:00:00
Expected Behavior
The results when the columns are ordering as such ["b", "a"] must be like that (order_2_df dataframe):
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
With the code above, the function
sum_of_subtraction
returns a different results if the columns of the input argumentvalues
are swapped (cf the example below).Yet, using
rolling
withmethod='table'
followed withapply
returns same results, no matter or the columns ordering. Even though the columns were given with a specific ordering, when callingapply
withengine='numba'
, the columns are sorted alphabetically. With the code above, here are the results:order_1_df
:order_2_df
:Expected Behavior
The results when the columns are ordering as such
["b", "a"]
must be like that (order_2_df
dataframe):Installed Versions