Repository: ml31415/numpy-groupies

Issue:
Different results in V0.9.14 than in V0.9.16
Hi, I was using this repo for a personal project and I decide to update the version and then I notice that the results of groupby aggregate function are totally different (I think that they are incorrect in the new version), here is an example:
```py
import numpy_groupies as npg
import numpy as np
x = np.array([
    [ 1.,  2.],
    [ 4.,  4.],
    [ 5.,  2.],
    [np.nan,  3.],
    [ 8.,  7.]]
)
group_idx = np.array([1, 2, 2, 0, 1])
func = 'nanmax'
fill_value = np.nan
axis=0
npg.aggregate(group_idx, x, axis=axis, func=func, fill_value=fill_value)

# Result with V0.9.14, which I think is correct, because it match with the Xarray code in the last part
array([[nan,  3.],
       [ 8.,  7.],
       [ 5.,  4.]])

# Result with V0.9.16, you can notice that both results contain the same values, but this in particular has a different order
array([[nan,  8.],
       [ 5.,  3.],
       [ 7.,  4.]])
```



```
# The expected result can be obtained using Xarray groupby, which is the same than in the V0.9.14
import xarray as xr

xr.DataArray(
    x,
    coords={
        'a': [0, 1, 2, 3, 4],
        'b': [0, 1]
    }
).groupby(
    xr.DataArray(
        group_idx,
        dims=['a']
    )
).max()
```

Discussion:

Patch:
diff --git a/numpy_groupies/utils_numpy.py b/numpy_groupies/utils_numpy.py
index 02616c2..5c9fe70 100644
--- a/numpy_groupies/utils_numpy.py
+++ b/numpy_groupies/utils_numpy.py
@@ -240,7 +240,7 @@ def offset_labels(group_idx, inshape, axis, order, size):
 
 
 def input_validation(group_idx, a, size=None, order='C', axis=None,
-                     ravel_group_idx=True, check_bounds=True, method="offset", func=None):
+                     ravel_group_idx=True, check_bounds=True, method="ravel", func=None):
     """ Do some fairly extensive checking of group_idx and a, trying to
     give the user as much help as possible with what is wrong. Also,
     convert ndim-indexing to 1d indexing.


Test patch:
diff --git a/numpy_groupies/tests/test_generic.py b/numpy_groupies/tests/test_generic.py
index cea8554..4739810 100644
--- a/numpy_groupies/tests/test_generic.py
+++ b/numpy_groupies/tests/test_generic.py
@@ -203,7 +203,7 @@ def test_scalar_input(aggregate_all, func):
         np.testing.assert_array_equal(res, ref)
 
 
-@pytest.mark.parametrize("func", ["sum", "prod", "mean", "var", "std" , "all", "any"])
+@pytest.mark.parametrize("func", ["sum", "prod", "mean", "var", "std", "all", "any"])
 def test_nan_input(aggregate_all, func, groups=100):
     if aggregate_all.__name__.endswith('pandas'):
         pytest.skip("pandas automatically skip nan values")
@@ -354,6 +354,25 @@ def test_agg_along_axis(aggregate_all, size, func, axis):
     np.testing.assert_allclose(actual.squeeze(), expected)
 
 
+def test_not_last_axis_reduction(aggregate_all):
+    x = np.array([
+        [1., 2.],
+        [4., 4.],
+        [5., 2.],
+        [np.nan, 3.],
+        [8., 7.]]
+    )
+    group_idx = np.array([1, 2, 2, 0, 1])
+    func = 'nanmax'
+    fill_value = np.nan
+    axis = 0
+    actual = aggregate_all(group_idx, x, axis=axis, func=func, fill_value=fill_value)
+    expected = np.array([[np.nan, 3.],
+                         [8., 7.],
+                         [5., 4.]])
+    np.testing.assert_allclose(expected, actual)
+
+
 def test_custom_callable(aggregate_all):
     def sum_(array):
         return array.sum()
@@ -379,6 +398,7 @@ def test_argreduction_nD_array_1D_idx(aggregate_all):
     expected = np.array([[0, 5, 2], [0, 5, 2]])
     np.testing.assert_equal(actual, expected)
 
+
 @pytest.mark.xfail(reason="fails for numba, pandas")
 def test_argreduction_negative_fill_value(aggregate_all):
     labels = np.array([0, 0, 2, 2, 2, 1, 1, 2, 2, 1, 1, 0], dtype=int)
@@ -388,7 +408,7 @@ def test_argreduction_negative_fill_value(aggregate_all):
     np.testing.assert_equal(actual, expected)
 
 
-@pytest.mark.parametrize("nan_inds", (None,  tuple([[1, 4, 5], Ellipsis]), tuple((1,(0, 1, 2, 3)))))
+@pytest.mark.parametrize("nan_inds", (None, tuple([[1, 4, 5], Ellipsis]), tuple((1, (0, 1, 2, 3)))))
 @pytest.mark.parametrize("ddof", (0, 1))
 @pytest.mark.parametrize("func", ("nanvar", "nanstd"))
 def test_var_with_nan_fill_value(aggregate_all, ddof, nan_inds, func):