TST: suppress gratuitous warnings in test_moments.py
State: closed

This PR suppresses expected warnings in test_moments.py, which are otherwise distracting.

Note that the changes are not nearly as extensive as they look. I simply indented blocks of code under newly added `with warnings.catch_warnings():`.


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

Comments:
can you post a sample warning. where are these coming from?

See below. There's one depracation warning; some from numpy complaining about empty/0-length arrays; and one about comparing objects (column labels) that can't be compared.

```
test_expanding_consistency (pandas.stats.tests.test_moments.TestMoments) ... C:\Python34\lib\site-packages\numpy\lib\function_base.py:1875: RuntimeWarning: Degrees of freedom <= 0 for slice
  warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning)
C:\Python34\lib\site-packages\numpy\lib\nanfunctions.py:1059: RuntimeWarning: Degrees of freedom <= 0 for slice.
  warnings.warn("Degrees of freedom <= 0 for slice.", RuntimeWarning)
C:\Python34\lib\site-packages\numpy\core\_methods.py:83: RuntimeWarning: Degrees of freedom <= 0 for slice
  warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning)
ok

test_moment_functions_zero_length (pandas.stats.tests.test_moments.TestMoments) ... c:\Users\seth\Documents\github\pandas\build\lib.win-amd64-3.4\pandas\stats\moments.py:347: FutureWarning: rolling_corr_pairwise is deprecated, use rolling_corr(..., pairwise=True)
  warnings.warn("rolling_corr_pairwise is deprecated, use rolling_corr(..., pairwise=True)", FutureWarning)
ok

test_pairwise_stats_column_names_order (pandas.stats.tests.test_moments.TestMoments) ... c:\Users\seth\Documents\github\pandas\build\lib.win-amd64-3.4\pandas\core\index.py:1218: RuntimeWarning: unorderable types: int() < str(), sort order is undefined for incomparable objects
  "incomparable objects" % e, RuntimeWarning)
c:\Users\seth\Documents\github\pandas\build\lib.win-amd64-3.4\pandas\core\index.py:1218: RuntimeWarning: unorderable types: float() < str(), sort order is undefined for incomparable objects
  "incomparable objects" % e, RuntimeWarning)
ok

test_rolling_apply (pandas.stats.tests.test_moments.TestMoments) ... C:\Python34\lib\site-packages\numpy\core\_methods.py:59: RuntimeWarning: Mean of empty slice.
  warnings.warn("Mean of empty slice.", RuntimeWarning)
ok
```

I thought I was also getting a warning in test_rolling_consistency(), though don't see one there now, so maybe it doesn't need the warnings-suppression code. Would have expected a numpy warning here about empty/0-length arrays, given that get one in test_expanding_consistency().

These are on the numpy_master build? (e.g. the one at the bottom of travis). 

hmm, maybe see what is causing them and may need to not pass certain things to numpy (e.g. if then len is 0), they are getting more strict esp in 1.9

Afraid I'm not sure where they are in Travis. The output I provided is from when I run:

```
C:\Python34\scripts\nosetests --verbosity=3 build\lib.win-amd64-3.4\pandas\stats
```

I think it might be a bit of a pain to test all the Pandas functions with empty/0-length objects, while (b) ensuring that we never pass an empty/0-length object to numpy. Probably doable, but would likely make the testing code more awkward.

Just updated the commit to leave test_rolling_consistency() unchanged, as it doesn't seem to be producing a warning.

Am not sure if these are from test_moments.py, but found these warnings in the 3rd, 4th, and 5th Travis builds:

https://travis-ci.org/pydata/pandas/jobs/35567015:

```
/home/travis/virtualenv/python2.7.8/lib/python2.7/site-packages/numpy/core/_methods.py:55: RuntimeWarning: Mean of empty slice.

warnings.warn("Mean of empty slice.", RuntimeWarning)

/home/travis/virtualenv/python2.7.8/lib/python2.7/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'str', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python2.7.8/lib/python2.7/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'int', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)
```

https://travis-ci.org/pydata/pandas/jobs/35567016:

```
/home/travis/virtualenv/python3.3.5/lib/python3.3/site-packages/pandas/core/index.py:1218: RuntimeWarning: unorderable types: float() < str(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

./home/travis/virtualenv/python3.3.5/lib/python3.3/site-packages/numpy/core/_methods.py:55: RuntimeWarning: Mean of empty slice.

warnings.warn("Mean of empty slice.", RuntimeWarning)

/home/travis/virtualenv/python3.3.5/lib/python3.3/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'str', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.3.5/lib/python3.3/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'int', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)
```

https://travis-ci.org/pydata/pandas/jobs/35567017:

```
/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1218: RuntimeWarning: unorderable types: str() < int(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1232: RuntimeWarning: unorderable types: str() > int(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1218: RuntimeWarning: unorderable types: int() < str(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1232: RuntimeWarning: unorderable types: int() > str(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1218: RuntimeWarning: unorderable types: float() < str(), sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

./home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/numpy/core/_methods.py:55: RuntimeWarning: Mean of empty slice.

warnings.warn("Mean of empty slice.", RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'str', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)

/home/travis/virtualenv/python3.4.1/lib/python3.4/site-packages/pandas/core/index.py:1218: RuntimeWarning: Cannot compare type 'Timestamp' with type 'int', sort order is undefined for incomparable objects

"incomparable objects" % e, RuntimeWarning)
```

yeh, these come up from the tests. most of these are ok, its the comparison part of the test that is triggering it (e.g. something numpy doesn't do right). but the pandas part is ok. If you want to have a look go ahead.

Well, since I've pretty much only been dealing with test_moments.py, I've focused only on getting that to run cleanly (i.e. this PR). Afraid I'm not too motivated to chase down other warnings at this time. :-(

thanks @seth-p