COMPAT: Further Expand Compatibility with fromnumeric.py
State: closed

Follow-on to #12810 by expanding compatibility with `fromnumeric.py` in the following modules:

1) `tslib.pyx`
2) `window.py`
3) `groupby.py` and `resample.py` (shared classes)

Closes #12811.


Labels:
name: Compat
description: pandas objects compatability with Numpy or Python functions

Comments:
## [Current coverage](https://codecov.io/gh/pydata/pandas/pull/13148?src=pr) is **84.14%**

> Merging [#13148](https://codecov.io/gh/pydata/pandas/pull/13148?src=pr) into [master](https://codecov.io/gh/pydata/pandas/branch/master?src=pr) will decrease coverage by **<.01%**

``` diff
@@             master     #13148   diff @@
==========================================
  Files           138        138          
  Lines         50394      50409    +15   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          42409      42416     +7   
- Misses         7985       7993     +8   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last updated by [2a120cf...e5465a6](https://codecov.io/gh/pydata/pandas/compare/2a120cf161ed3c71ee68063e9d13e3efd0d2c1e5...e5465a6b67eeae3e0c931eb077fcf78864a70aaa)

@gfyoung let's maybe just disallow using numpy functions on window/groupby ops (the `Timestamp` one is prob ok).

this should just raise a nicer error message (say this is not supported)

```
In [6]: np.mean(Series(range(3)).groupby(range(3)))
TypeError: mean() got an unexpected keyword argument 'axis'
```

Fair enough.  So instead of validating as I do now, I just check if the `args` or `kwargs` contain any `numpy`-specific arguments (not sure how else to check if the `pandas` function is being called from `numpy` otherwise)?

not really sure how to figure out if called via numpy w/o stack inspection (not a good idea!).

though you could simply just have it raise when it validates, e.g. its sort of duck like in the argument signature when called from numpy. IOW numpy is always passing dtype/out I think. So just raise a nicer error message on that (you prob need to pass a parameter to your validation routines to say hey if this is not validation, then print this nice error message; e.g. you want to say something like)

""" numpy operations are not valid with groupy, use `.groupby(...).mean()` instead 

@jreback, @jorisvandenbossche  : Made the changes, and Travis is giving the green light.  Ready to merge if there is nothing else.

thanks @gfyoung 

@gfyoung breaking with numpy master on rounding: https://travis-ci.org/pydata/pandas/jobs/131735642

Okay, I think we might need to undo this compatibility change to `tslib.pyx`.  If anyone complains about it, say that "`round` in `numpy` is for arrays and not timestamps, and you shouldn't be doing that" (currently, the function will throw an error because keyword arguments like `decimals` and `out` are not in the signature and shouldn't be).  Here is why:

``` python
# signature in tslib.pyx
def round(self, freq, *args, **kwargs):
...

# signature in numpy master
def around(a, decimals=0, out=None):
    return _wrapfunc(a, 'round', decimals=decimals, out=out)
```

When we call `np.round(timestamp, freq)`, `freq` is being passed in as the `decimals` argument.  However, `decimals` is being passed in with a `**kwargs` bundle, so it isn't being picked up as the positional argument needed for `freq`.  I forgot that that change was not in `v1.11.0` but was in `master`.  My bad for not checking.

ok so just revert that part of the PR
compat for timestamps is not s big deal for this