Skip to content

Instantly share code, notes, and snippets.

@TomAugspurger
Created March 30, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomAugspurger/b119546b318ab8f31ee4c7ffc8dce5f6 to your computer and use it in GitHub Desktop.
Save TomAugspurger/b119546b318ab8f31ee4c7ffc8dce5f6 to your computer and use it in GitHub Desktop.
============================= test session starts ==============================
platform darwin -- Python 3.7.0b3, pytest-3.5.0, py-1.5.3, pluggy-0.6.0
rootdir: /Users/taugspurger/sandbox/pandas, inifile: setup.cfg
plugins: xdist-1.22.2, forked-0.2, cov-2.5.1
gw0 I / gw1 I / gw2 I / gw3 I
gw0 [25237] / gw1 [25237] / gw2 [25237] / gw3 [25237]
scheduling tests via LoadScheduling
.....................................X.................................. [ 0%]
........................................................................ [ 0%]
........................................................................ [ 0%]
s.s......................................x.........................s..s. [ 1%]
......................................................s................. [ 1%]
.............ss......................................................... [ 1%]
........................................................................ [ 1%]
..........................s............................................. [ 2%]
........................................................................ [ 2%]
........................................................................ [ 2%]
........................................................................ [ 3%]
........................s......s........................................ [ 3%]
...............................................s.F...................... [ 3%]
...........s.............s..................................s........... [ 3%]
.....................................................................s.. [ 4%]
.......................s................................................ [ 4%]
........................................................................ [ 4%]
....x....s.............................................................. [ 5%]
........................................................................ [ 5%]
.......................s...............................x................ [ 5%]
........................................................................ [ 5%]
........................................................................ [ 6%]
................................................s.s.s.s................. [ 6%]
........................................................................ [ 6%]
........................................................................ [ 7%]
........................................................................ [ 7%]
....s..............................x....................X..s............ [ 7%]
........................................................................ [ 7%]
.................................x...................................... [ 8%]
........................................................................ [ 8%]
........................................................................ [ 8%]
........................................................................ [ 9%]
........................................................................ [ 9%]
....................................................................s.s. [ 9%]
.........ss.....................s....................................... [ 9%]
........................................................................ [ 10%]
........................................................................ [ 10%]
........................................................................ [ 10%]
...............................................................s....s... [ 11%]
.s......x...........X....................s..s........................... [ 11%]
..............................................................x......... [ 11%]
........................................................................ [ 11%]
........................................................................ [ 12%]
........................................................................ [ 12%]
........................................................................ [ 12%]
........................................................................ [ 13%]
........................................................................ [ 13%]
........................................................................ [ 13%]
.....s.ss....................................................s.......... [ 13%]
...............s......s..s..................s.s.......s............X.... [ 14%]
ss.................x...............X....s............................... [ 14%]
........................................................................ [ 14%]
........................................................................ [ 15%]
........................................................................ [ 15%]
........................................................................ [ 15%]
........................................................................ [ 15%]
...........................................x............................ [ 16%]
......................................ss.s.........s...s................ [ 16%]
...........s............................................................ [ 16%]
........................................................................ [ 17%]
........................................................................ [ 17%]
........................................................................ [ 17%]
......................................................................... [ 17%]
........................................................................ [ 18%]
........................................................................ [ 18%]
........................................................................ [ 18%]
...........................................................x.s......s... [ 19%]
.s...........................x..............................s........... [ 19%]
..............................................................x......... [ 19%]
........................................................................ [ 19%]
.................................................x...................... [ 20%]
................................s....................................... [ 20%]
........................................................................ [ 20%]
........s......................................ss........s..s......ss..s [ 21%]
........................s............................................... [ 21%]
........................................................................ [ 21%]
.....................................x.................................. [ 21%]
........................................................................ [ 22%]
........................................................................ [ 22%]
........................................................................ [ 22%]
..................................s..................................... [ 23%]
........................................................................ [ 23%]
........................................................................ [ 23%]
........................................................................ [ 23%]
........................................................................ [ 24%]
........................................................................ [ 24%]
..............................s......................................... [ 24%]
........................................................................ [ 25%]
........................................................................ [ 25%]
........................................................................ [ 25%]
........................................................................ [ 25%]
.....................s.................................................. [ 26%]
........................................................................ [ 26%]
........................................................................ [ 26%]
........................................................................ [ 27%]
........................................................................ [ 27%]
........................................................................ [ 27%]
......................................................................... [ 27%]
..............................................................x......... [ 28%]
.................................................x...................... [ 28%]
........................................................................ [ 28%]
........................................................................ [ 29%]
........................................................................ [ 29%]
........................................................................ [ 29%]
........................................................................ [ 29%]
......................................................................... [ 30%]
........................................................................ [ 30%]
........................................................................ [ 30%]
............x........................................................... [ 31%]
........................................................................ [ 31%]
........................................................................ [ 31%]
........................................................................ [ 31%]
........................................................ss.............. [ 32%]
........................................................................ [ 32%]
........................................................................ [ 32%]
........................................................................ [ 33%]
........................................................................ [ 33%]
....................................s.s................................. [ 33%]
....................................sss................................. [ 33%]
........................................................................ [ 34%]
........................................................................ [ 34%]
.........................ss............................................. [ 34%]
........................................................................ [ 35%]
........................................sss..........................sss [ 35%]
sssssssssssssssss.sssssssssssssssssssssssssssssssss.ssssssssssssssssssss [ 35%]
ssssssssssss.sssssssssssssssssssssssssssssssss.sssssssssssssssssssssssss [ 35%]
ssssss.sssssssssssssssssssssssssssss.sssssssssssssssssssssssssssssss.sss [ 36%]
sssssssssssssssssssssssssss.ssss..ss.s.ssss..ssss.ssssss.ssss.ss.ss.ssss [ 36%]
ss.ssss.sss.sss.ssssssssssssssssssssssssssssssssssssss.sssssssssssssssss [ 36%]
ssssssssssssssssssss.ssssssss.ssssss.ss.ss.sss.s.ss.ss.ssss.s.ssss.ss... [ 37%]
........................................................................ [ 37%]
................s....................................................... [ 37%]
..............................................x......................... [ 37%]
..................x...................................................x. [ 38%]
........................................................................ [ 38%]
........................................................................ [ 38%]
........................................................................ [ 39%]
........................................................................ [ 39%]
........................................................................ [ 39%]
........................................................................ [ 39%]
........................................................................ [ 40%]
........................................................................ [ 40%]
........................................................................ [ 40%]
........................................................................ [ 41%]
........................................................................ [ 41%]
........................................................................ [ 41%]
........................................................................ [ 41%]
........................................................................ [ 42%]
........................................................................ [ 42%]
........................................................................ [ 42%]
........................................................................ [ 43%]
........................................................................ [ 43%]
........................................................................ [ 43%]
........................................................................ [ 43%]
........................................................................ [ 44%]
..........................................x...x........xxxx............. [ 44%]
........x..........................xx....................s.......s...... [ 44%]
.........x....x...x..................................................... [ 45%]
........................................................................ [ 45%]
......s.s.s.s.s.s.s.s.s................................................. [ 45%]
........................xX.............................................. [ 45%]
........................................................................ [ 46%]
........................................................................ [ 46%]
........................................................................ [ 46%]
........................................................................ [ 47%]
........................................................................ [ 47%]
.............................................s.s.s..s..s.s.s.s.......... [ 47%]
........................................................................ [ 47%]
........................................................................ [ 48%]
...............................................x........................ [ 48%]
....s................................................................... [ 48%]
.................ssssss................................................. [ 49%]
.....................s.......s.......s.......s..s..ss.ss.....s.......... [ 49%]
.........................................ss.........ss.......s......s... [ 49%]
...F....F....F.......................................................... [ 49%]
........................................................................ [ 50%]
........................................................................ [ 50%]
....................................F.................................... [ 50%]
........................................................................ [ 51%]
........................................................................ [ 51%]
........................................................................ [ 51%]
........................................................................ [ 51%]
........................................................................ [ 52%]
......................F................................................. [ 52%]
........................................................................ [ 52%]
.........F.............................................................. [ 53%]
.................F....s...s....s........................................ [ 53%]
........................................................................ [ 53%]
........................................................................ [ 53%]
........................................................................ [ 54%]
........................................................................ [ 54%]
...................................................x....x....x...x...x.x [ 54%]
xx.x..x....x......................................................F..... [ 55%]
........................................................................ [ 55%]
........................................s............................... [ 55%]
......................................................s..........s...... [ 55%]
........ssssssssssss.ss.ssssssssssssssssssss.ssssssss..s................ [ 56%]
........................................................................ [ 56%]
.................s...................................................... [ 56%]
........................................................................ [ 57%]
........................................................................ [ 57%]
........................................................................ [ 57%]
........................................................................ [ 57%]
........................................................................ [ 58%]
........................................................................ [ 58%]
.......x................................................................ [ 58%]
........................................................................ [ 59%]
........................................................................ [ 59%]
........................................................................ [ 59%]
...................................................x.................... [ 59%]
........................................................................ [ 60%]
......................................................................... [ 60%]
....................................................................ss.. [ 60%]
........................................................................ [ 61%]
........................................................................ [ 61%]
........................................................................ [ 61%]
........................................................................ [ 61%]
........................................................................ [ 62%]
........................................................................ [ 62%]
........................................................................ [ 62%]
................................................s....................... [ 63%]
........................................................................ [ 63%]
........................................................................ [ 63%]
.......s................................................................ [ 63%]
..........................x............................................. [ 64%]
.......................................................s................ [ 64%]
..................................................s.ss.................. [ 64%]
.....................................................................sss [ 65%]
ss...................................................................... [ 65%]
....s................................................s..s..s.s.s..s..s.. [ 65%]
s.s.s..ss..........................................................s.... [ 65%]
..................................s..................................... [ 66%]
........................s.....s........sssssssssssssssssssssssssssssssss [ 66%]
sssss.sssssssssssssssssssssssssssssssssssss.s........................... [ 66%]
...........s..............X............................................. [ 67%]
..................s...........s......................................... [ 67%]
........................s............................................... [ 67%]
...........s.......................ssssssssss........................... [ 67%]
............s........................................................... [ 68%]
........................................................................ [ 68%]
........................................................................ [ 68%]
....s................................................................... [ 69%]
.....................s.................................................. [ 69%]
X......................................s................................ [ 69%]
........................................................................ [ 69%]
.X...................................................................... [ 70%]
.................x...................................................... [ 70%]
........................................................................ [ 70%]
..........................................................X............. [ 71%]
........................................................................ [ 71%]
........................................................................ [ 71%]
........................................................................ [ 71%]
........................................................................ [ 72%]
........................................................................ [ 72%]
...............s........................................................ [ 72%]
........................................................................ [ 73%]
..............s......................................................... [ 73%]
.........................................................x.....x........ [ 73%]
........................................................................ [ 73%]
........................................................................ [ 74%]
....................................................................x.x. [ 74%]
........................xxxxxxxXXX...................................... [ 74%]
....................................................XXXXXXXXXX.......... [ 75%]
......XX................................................................ [ 75%]
........................................................................ [ 75%]
........................................................................ [ 75%]
........................................................................ [ 76%]
........................................................................ [ 76%]
......................................s................................. [ 76%]
........................................................................ [ 77%]
........................................................................ [ 77%]
........................................................................ [ 77%]
........................................................................ [ 77%]
....................ssss................................................ [ 78%]
................................s.....x...s............................. [ 78%]
........................................................................ [ 78%]
........................................................................ [ 79%]
.....................................................s.................. [ 79%]
........................................................................ [ 79%]
........................................................................ [ 79%]
..........................................................s............. [ 80%]
........................................................................ [ 80%]
........................................................................ [ 80%]
........................................................................ [ 81%]
........................................................................ [ 81%]
............................s........................................... [ 81%]
........................................................................ [ 81%]
........................................................................ [ 82%]
........................................................................ [ 82%]
....................x..x...........................x.................... [ 82%]
........................................................................ [ 83%]
.........................................................x.............. [ 83%]
...............................................x........................ [ 83%]
.........x....sss.sss.sss.sss.sss.sss.ss................................ [ 83%]
........................................................................ [ 84%]
........................................................................ [ 84%]
........................................................................ [ 84%]
........................................................................ [ 85%]
........................................................................ [ 85%]
........................................................................ [ 85%]
.............................................sss........................ [ 85%]
.ssssss.ssssssssss.ssss................................................. [ 86%]
.....................................s.................................. [ 86%]
........................................................................ [ 86%]
......................................................................... [ 87%]
........................................................................ [ 87%]
........................................................................ [ 87%]
........................................................................ [ 87%]
........................................................................ [ 88%]
........................................................................ [ 88%]
........................................................................ [ 88%]
......................................................................... [ 89%]
.............F.......................................................... [ 89%]
........................................................................ [ 89%]
.......................................................F................. [ 89%]
........................................................................ [ 90%]
........................................................................ [ 90%]
........................................................................ [ 90%]
........................................................................ [ 91%]
........................................................................ [ 91%]
........................................................................ [ 91%]
......................................................................... [ 91%]
........................................................................ [ 92%]
........................................................................ [ 92%]
......................................................................... [ 92%]
..................................X..................................... [ 93%]
........................................................................ [ 93%]
......................................................................... [ 93%]
........................................................................ [ 93%]
........................................................................ [ 94%]
...sss.................................................................. [ 94%]
........................................................................ [ 94%]
........................................................................ [ 95%]
........................................................................ [ 95%]
........................................................................ [ 95%]
........................................................................ [ 95%]
........................................................................ [ 96%]
........................................................................ [ 96%]
...............................s........................................ [ 96%]
........................................................................ [ 97%]
.........................x...x.................xx....................... [ 97%]
...................................xxxxx................................ [ 97%]
.............................................................ss......... [ 97%]
..............................x......................x.................. [ 98%]
........................................................................ [ 98%]
........................................................................ [ 98%]
........................................................................ [ 99%]
........................................................................ [ 99%]
........................................................................ [ 99%]
........................................................................ [ 99%]
.......................... [100%]
=================================== FAILURES ===================================
________________________ TestResampleAPI.test_plot_api _________________________
[gw0] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.test_resample.TestResampleAPI object at 0x11f91f0f0>
@td.skip_if_no_mpl
def test_plot_api(self):
# .resample(....).plot(...)
# hitting warnings
# GH 12448
s = Series(np.random.randn(60),
index=date_range('2016-01-01', periods=60, freq='1min'))
with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
result = s.resample('15min').plot()
> tm.assert_is_valid_plot_return_object(result)
pandas/tests/test_resample.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'FutureWarning'>, filter_level = 'always'
clear = None, check_stacklevel = False
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
assert actual_warning.filename == caller.filename, msg
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
msg = "Did not see expected warning of class {name!r}.".format(
name=expected_warning.__name__)
assert saw_warning, msg
assert not extra_warnings, ("Caused unexpected warning(s): {extra!r}."
> ).format(extra=extra_warnings)
E AssertionError: Caused unexpected warning(s): ['DeprecationWarning'].
pandas/util/testing.py:2531: AssertionError
____________________ TestXlrdReader.test_usecols_int[.xls] _____________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x119396390>
ext = '.xls'
def test_usecols_int(self, ext):
dfref = self.get_csv_refdf('test1')
dfref = dfref.reindex(columns=['A', 'B', 'C'])
df1 = self.get_exceldf('test1', ext, 'Sheet1', index_col=0, usecols=3)
df2 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
index_col=0, usecols=3)
with tm.assert_produces_warning(FutureWarning):
df3 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
> index_col=0, parse_cols=3)
pandas/tests/io/test_excel.py:121:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'FutureWarning'>, filter_level = 'always'
clear = None, check_stacklevel = True
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
assert actual_warning.filename == caller.filename, msg
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
msg = "Did not see expected warning of class {name!r}.".format(
name=expected_warning.__name__)
assert saw_warning, msg
assert not extra_warnings, ("Caused unexpected warning(s): {extra!r}."
> ).format(extra=extra_warnings)
E AssertionError: Caused unexpected warning(s): ['DeprecationWarning', 'DeprecationWarning', 'DeprecationWarning'].
pandas/util/testing.py:2531: AssertionError
____________________ TestXlrdReader.test_usecols_list[.xls] ____________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x1166fb198>
ext = '.xls'
def test_usecols_list(self, ext):
dfref = self.get_csv_refdf('test1')
dfref = dfref.reindex(columns=['B', 'C'])
df1 = self.get_exceldf('test1', ext, 'Sheet1', index_col=0,
usecols=[0, 2, 3])
df2 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
index_col=0, usecols=[0, 2, 3])
with tm.assert_produces_warning(FutureWarning):
df3 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
> index_col=0, parse_cols=[0, 2, 3])
pandas/tests/io/test_excel.py:139:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'FutureWarning'>, filter_level = 'always'
clear = None, check_stacklevel = True
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
assert actual_warning.filename == caller.filename, msg
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
msg = "Did not see expected warning of class {name!r}.".format(
name=expected_warning.__name__)
assert saw_warning, msg
assert not extra_warnings, ("Caused unexpected warning(s): {extra!r}."
> ).format(extra=extra_warnings)
E AssertionError: Caused unexpected warning(s): ['DeprecationWarning', 'DeprecationWarning', 'DeprecationWarning'].
pandas/util/testing.py:2531: AssertionError
____________________ TestXlrdReader.test_usecols_str[.xls] _____________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x119396198>
ext = '.xls'
def test_usecols_str(self, ext):
dfref = self.get_csv_refdf('test1')
df1 = dfref.reindex(columns=['A', 'B', 'C'])
df2 = self.get_exceldf('test1', ext, 'Sheet1', index_col=0,
usecols='A:D')
df3 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
index_col=0, usecols='A:D')
with tm.assert_produces_warning(FutureWarning):
df4 = self.get_exceldf('test1', ext, 'Sheet2', skiprows=[1],
> index_col=0, parse_cols='A:D')
pandas/tests/io/test_excel.py:158:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'FutureWarning'>, filter_level = 'always'
clear = None, check_stacklevel = True
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
assert actual_warning.filename == caller.filename, msg
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
msg = "Did not see expected warning of class {name!r}.".format(
name=expected_warning.__name__)
assert saw_warning, msg
assert not extra_warnings, ("Caused unexpected warning(s): {extra!r}."
> ).format(extra=extra_warnings)
E AssertionError: Caused unexpected warning(s): ['DeprecationWarning', 'DeprecationWarning', 'DeprecationWarning'].
pandas/util/testing.py:2531: AssertionError
______________ TestXlrdReader.test_sheet_name_and_sheetname[.xls] ______________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x11509cb38>
ext = '.xls'
def test_sheet_name_and_sheetname(self, ext):
# GH10559: Minor improvement: Change "sheet_name" to "sheetname"
# GH10969: DOC: Consistent var names (sheetname vs sheet_name)
# GH12604: CLN GH10559 Rename sheetname variable to sheet_name
dfref = self.get_csv_refdf('test1')
df1 = self.get_exceldf('test1', ext, sheet_name='Sheet1') # doc
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
df2 = self.get_exceldf('test1', ext,
> sheetname='Sheet1') # bkwrd compat
pandas/tests/io/test_excel.py:511:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'FutureWarning'>, filter_level = 'always'
clear = None, check_stacklevel = False
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
assert actual_warning.filename == caller.filename, msg
else:
extra_warnings.append(actual_warning.category.__name__)
if expected_warning:
msg = "Did not see expected warning of class {name!r}.".format(
name=expected_warning.__name__)
assert saw_warning, msg
assert not extra_warnings, ("Caused unexpected warning(s): {extra!r}."
> ).format(extra=extra_warnings)
E AssertionError: Caused unexpected warning(s): ['DeprecationWarning', 'DeprecationWarning', 'DeprecationWarning'].
pandas/util/testing.py:2531: AssertionError
_________________ TestXlrdReader.test_read_from_http_url[.xls] _________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x114fedfd0>
ext = '.xls'
@tm.network
def test_read_from_http_url(self, ext):
url = ('https://raw.github.com/pandas-dev/pandas/master/'
'pandas/tests/io/data/test1' + ext)
> url_table = read_excel(url)
pandas/tests/io/test_excel.py:562:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/io/excel.py:315: in read_excel
io = ExcelFile(io, engine=engine)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pandas.io.excel.ExcelFile object at 0x115340fd0>
io = <http.client.HTTPResponse object at 0x115a102e8>, kwds = {}
err_msg = 'Install xlrd >= 0.9.0 for Excel support'
xlrd = <module 'xlrd' from '/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/xlrd/__init__.py'>
ver = (1, 1), engine = None
def __init__(self, io, **kwds):
err_msg = "Install xlrd >= 0.9.0 for Excel support"
try:
import xlrd
except ImportError:
raise ImportError(err_msg)
else:
ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
if ver < (0, 9): # pragma: no cover
raise ImportError(err_msg +
". Current version " + xlrd.__VERSION__)
# could be a str, ExcelFile, Book, etc.
self.io = io
# Always a string
self._io = _stringify_path(io)
engine = kwds.pop('engine', None)
if engine is not None and engine != 'xlrd':
raise ValueError("Unknown engine: {engine}".format(engine=engine))
# If io is a url, want to keep the data as bytes so can't pass
# to get_filepath_or_buffer()
if _is_url(self._io):
io = _urlopen(self._io)
elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
io, _, _, _ = get_filepath_or_buffer(self._io)
if engine == 'xlrd' and isinstance(io, xlrd.Book):
self.book = io
elif not isinstance(io, xlrd.Book) and hasattr(io, "read"):
# N.B. xlrd.Book has a read attribute too
if hasattr(io, 'seek'):
# GH 19779
> io.seek(0)
E io.UnsupportedOperation: seek
pandas/io/excel.py:392: UnsupportedOperation
________________ TestXlrdReader.test_read_from_http_url[.xlsx] _________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x115c5ebe0>
ext = '.xlsx'
@tm.network
def test_read_from_http_url(self, ext):
url = ('https://raw.github.com/pandas-dev/pandas/master/'
'pandas/tests/io/data/test1' + ext)
> url_table = read_excel(url)
pandas/tests/io/test_excel.py:562:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/io/excel.py:315: in read_excel
io = ExcelFile(io, engine=engine)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pandas.io.excel.ExcelFile object at 0x115c5e438>
io = <http.client.HTTPResponse object at 0x115c5e588>, kwds = {}
err_msg = 'Install xlrd >= 0.9.0 for Excel support'
xlrd = <module 'xlrd' from '/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/xlrd/__init__.py'>
ver = (1, 1), engine = None
def __init__(self, io, **kwds):
err_msg = "Install xlrd >= 0.9.0 for Excel support"
try:
import xlrd
except ImportError:
raise ImportError(err_msg)
else:
ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
if ver < (0, 9): # pragma: no cover
raise ImportError(err_msg +
". Current version " + xlrd.__VERSION__)
# could be a str, ExcelFile, Book, etc.
self.io = io
# Always a string
self._io = _stringify_path(io)
engine = kwds.pop('engine', None)
if engine is not None and engine != 'xlrd':
raise ValueError("Unknown engine: {engine}".format(engine=engine))
# If io is a url, want to keep the data as bytes so can't pass
# to get_filepath_or_buffer()
if _is_url(self._io):
io = _urlopen(self._io)
elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
io, _, _, _ = get_filepath_or_buffer(self._io)
if engine == 'xlrd' and isinstance(io, xlrd.Book):
self.book = io
elif not isinstance(io, xlrd.Book) and hasattr(io, "read"):
# N.B. xlrd.Book has a read attribute too
if hasattr(io, 'seek'):
# GH 19779
> io.seek(0)
E io.UnsupportedOperation: seek
pandas/io/excel.py:392: UnsupportedOperation
________________ TestXlrdReader.test_read_from_http_url[.xlsm] _________________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x115b23a90>
ext = '.xlsm'
@tm.network
def test_read_from_http_url(self, ext):
url = ('https://raw.github.com/pandas-dev/pandas/master/'
'pandas/tests/io/data/test1' + ext)
> url_table = read_excel(url)
pandas/tests/io/test_excel.py:562:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/util/_decorators.py:177: in wrapper
return func(*args, **kwargs)
pandas/io/excel.py:315: in read_excel
io = ExcelFile(io, engine=engine)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pandas.io.excel.ExcelFile object at 0x115b23e80>
io = <http.client.HTTPResponse object at 0x115b234a8>, kwds = {}
err_msg = 'Install xlrd >= 0.9.0 for Excel support'
xlrd = <module 'xlrd' from '/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/xlrd/__init__.py'>
ver = (1, 1), engine = None
def __init__(self, io, **kwds):
err_msg = "Install xlrd >= 0.9.0 for Excel support"
try:
import xlrd
except ImportError:
raise ImportError(err_msg)
else:
ver = tuple(map(int, xlrd.__VERSION__.split(".")[:2]))
if ver < (0, 9): # pragma: no cover
raise ImportError(err_msg +
". Current version " + xlrd.__VERSION__)
# could be a str, ExcelFile, Book, etc.
self.io = io
# Always a string
self._io = _stringify_path(io)
engine = kwds.pop('engine', None)
if engine is not None and engine != 'xlrd':
raise ValueError("Unknown engine: {engine}".format(engine=engine))
# If io is a url, want to keep the data as bytes so can't pass
# to get_filepath_or_buffer()
if _is_url(self._io):
io = _urlopen(self._io)
elif not isinstance(self.io, (ExcelFile, xlrd.Book)):
io, _, _, _ = get_filepath_or_buffer(self._io)
if engine == 'xlrd' and isinstance(io, xlrd.Book):
self.book = io
elif not isinstance(io, xlrd.Book) and hasattr(io, "read"):
# N.B. xlrd.Book has a read attribute too
if hasattr(io, 'seek'):
# GH 19779
> io.seek(0)
E io.UnsupportedOperation: seek
pandas/io/excel.py:392: UnsupportedOperation
_______________ TestXlrdReader.test_read_excel_parse_dates[.xls] _______________
[gw3] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.io.test_excel.TestXlrdReader object at 0x115b41358>
ext = '.xls'
@td.skip_if_no('openpyxl')
@td.skip_if_no('xlwt')
def test_read_excel_parse_dates(self, ext):
# GH 11544, 12051
df = DataFrame(
{'col': [1, 2, 3],
'date_strings': pd.date_range('2012-01-01', periods=3)})
df2 = df.copy()
df2['date_strings'] = df2['date_strings'].dt.strftime('%m/%d/%Y')
with ensure_clean(ext) as pth:
df2.to_excel(pth)
res = read_excel(pth)
tm.assert_frame_equal(df2, res)
# no index_col specified when parse_dates is True
with tm.assert_produces_warning():
res = read_excel(pth, parse_dates=True)
> tm.assert_frame_equal(df2, res)
pandas/tests/io/test_excel.py:938:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../cpython/Lib/contextlib.py:119: in __exit__
next(self.gen)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected_warning = <class 'Warning'>, filter_level = 'always', clear = None
check_stacklevel = True
@contextmanager
def assert_produces_warning(expected_warning=Warning, filter_level="always",
clear=None, check_stacklevel=True):
"""
Context manager for running code expected to either raise a specific
warning, or not raise any warnings. Verifies that the code raises the
expected warning, and that it does not raise any other unexpected
warnings. It is basically a wrapper around ``warnings.catch_warnings``.
Parameters
----------
expected_warning : {Warning, False, None}, default Warning
The type of Exception raised. ``exception.Warning`` is the base
class for all warnings. To check that no warning is returned,
specify ``False`` or ``None``.
filter_level : str, default "always"
Specifies whether warnings are ignored, displayed, or turned
into errors.
Valid values are:
* "error" - turns matching warnings into exceptions
* "ignore" - discard the warning
* "always" - always emit a warning
* "default" - print the warning the first time it is generated
from each location
* "module" - print the warning the first time it is generated
from each module
* "once" - print the warning the first time it is generated
clear : str, default None
If not ``None`` then remove any previously raised warnings from
the ``__warningsregistry__`` to ensure that no warning messages are
suppressed by this context manager. If ``None`` is specified,
the ``__warningsregistry__`` keeps track of which warnings have been
shown, and does not show them again.
check_stacklevel : bool, default True
If True, displays the line that called the function containing
the warning to show were the function is called. Otherwise, the
line that implements the function is displayed.
Examples
--------
>>> import warnings
>>> with assert_produces_warning():
... warnings.warn(UserWarning())
...
>>> with assert_produces_warning(False):
... warnings.warn(RuntimeWarning())
...
Traceback (most recent call last):
...
AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
>>> with assert_produces_warning(UserWarning):
... warnings.warn(RuntimeWarning())
Traceback (most recent call last):
...
AssertionError: Did not see expected warning of class 'UserWarning'.
..warn:: This is *not* thread-safe.
"""
with warnings.catch_warnings(record=True) as w:
if clear is not None:
# make sure that we are clearning these warnings
# if they have happened before
# to guarantee that we will catch them
if not is_list_like(clear):
clear = [clear]
for m in clear:
try:
m.__warningregistry__.clear()
except Exception:
pass
saw_warning = False
warnings.simplefilter(filter_level)
yield w
extra_warnings = []
for actual_warning in w:
if (expected_warning and issubclass(actual_warning.category,
expected_warning)):
saw_warning = True
if check_stacklevel and issubclass(actual_warning.category,
(FutureWarning,
DeprecationWarning)):
from inspect import getframeinfo, stack
caller = getframeinfo(stack()[2][0])
msg = ("Warning not set with correct stacklevel. "
"File where warning is raised: {actual} != "
"{caller}. Warning message: {message}"
).format(actual=actual_warning.filename,
caller=caller.filename,
message=actual_warning.message)
> assert actual_warning.filename == caller.filename, msg
E AssertionError: Warning not set with correct stacklevel. File where warning is raised: /Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/xlrd/book.py != /Users/taugspurger/sandbox/pandas/pandas/tests/io/test_excel.py. Warning message: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
pandas/util/testing.py:2523: AssertionError
__________________________ TestBusinessDay.test_repr ___________________________
[gw2] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.tseries.offsets.test_offsets.TestBusinessDay object at 0x11b693668>
def test_repr(self):
assert repr(self.offset) == '<BusinessDay>'
assert repr(self.offset2) == '<2 * BusinessDays>'
expected = '<BusinessDay: offset=datetime.timedelta(1)>'
> assert repr(self.offset + timedelta(1)) == expected
E AssertionError: assert '<BusinessDay...elta(days=1)>' == '<BusinessDay:...timedelta(1)>'
E - <BusinessDay: offset=datetime.timedelta(days=1)>
E ? -----
E + <BusinessDay: offset=datetime.timedelta(1)>
pandas/tests/tseries/offsets/test_offsets.py:532: AssertionError
_______________________ TestCustomBusinessDay.test_repr ________________________
[gw2] darwin -- Python 3.7.0 /Users/taugspurger/Envs/pandas/bin/python
self = <pandas.tests.tseries.offsets.test_offsets.TestCustomBusinessDay object at 0x11c296470>
def test_repr(self):
assert repr(self.offset) == '<CustomBusinessDay>'
assert repr(self.offset2) == '<2 * CustomBusinessDays>'
expected = '<BusinessDay: offset=datetime.timedelta(1)>'
> assert repr(self.offset + timedelta(1)) == expected
E AssertionError: assert '<BusinessDay...elta(days=1)>' == '<BusinessDay:...timedelta(1)>'
E - <BusinessDay: offset=datetime.timedelta(days=1)>
E ? -----
E + <BusinessDay: offset=datetime.timedelta(1)>
pandas/tests/tseries/offsets/test_offsets.py:1646: AssertionError
=============================== warnings summary ===============================
pandas/tests/test_expressions.py::TestExpressions::()::test_float_panel
/Users/taugspurger/sandbox/pandas/pandas/core/panel.py:742: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, func)
/Users/taugspurger/sandbox/pandas/pandas/core/ops.py:1650: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, na_op, try_cast=False)
pandas/tests/test_expressions.py::TestExpressions::()::test_mixed_panel
/Users/taugspurger/sandbox/pandas/pandas/core/panel.py:742: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, func)
/Users/taugspurger/sandbox/pandas/pandas/core/ops.py:1650: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, na_op, try_cast=False)
pandas/tests/test_expressions.py::TestExpressions::()::test_integer_panel
/Users/taugspurger/sandbox/pandas/pandas/core/panel.py:742: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, func)
/Users/taugspurger/sandbox/pandas/pandas/core/ops.py:1650: FutureWarning:
Panel is deprecated and will be removed in a future version.
The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method
Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.
Pandas provides a `.to_xarray()` method to help automate this conversion.
return self._combine_const(other, na_op, try_cast=False)
pandas/tests/test_multilevel.py::TestMultiLevel::()::test_frame_group_ops[False]
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/numpy/core/_methods.py:29: RuntimeWarning: invalid value encountered in reduce
return umr_minimum(a, axis, None, out, keepdims)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/numpy/core/_methods.py:26: RuntimeWarning: invalid value encountered in reduce
return umr_maximum(a, axis, None, out, keepdims)
pandas/tests/test_multilevel.py::TestMultiLevel::()::test_frame_group_ops[True]
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/numpy/core/_methods.py:29: RuntimeWarning: invalid value encountered in reduce
return umr_minimum(a, axis, None, out, keepdims)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/numpy/core/_methods.py:26: RuntimeWarning: invalid value encountered in reduce
return umr_maximum(a, axis, None, out, keepdims)
pandas/tests/test_resample.py::TestResamplerGrouper::()::test_tab_complete_ipython6_warning
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/IPython/core/interactiveshell.py:728: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
pandas/tests/categorical/test_warnings.py::TestCategoricalWarnings::()::test_tab_complete_warning
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/IPython/core/interactiveshell.py:728: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
pandas/tests/frame/test_api.py::TestDataFrameMisc::()::test_tab_complete_warning
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/IPython/core/interactiveshell.py:728: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
pandas/tests/frame/test_missing.py::TestDataFrameMissingData::()::test_fillna_categorical_nan
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/numpy/lib/function_base.py:3229: RuntimeWarning: All-NaN slice encountered
r = func(a, **kwargs)
pandas/tests/io/formats/test_printing.py::TestTableSchemaRepr::()::test_publishes
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/IPython/core/interactiveshell.py:728: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
pandas/tests/plotting/test_frame.py::TestDataFramePlots::()::test_errorbar_plot
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
pandas/tests/plotting/test_frame.py::TestDataFramePlots::()::test_errorbar_timeseries
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:1796: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
plot_obj.generate()
pandas/tests/plotting/test_hist_method.py::TestSeriesPlots::()::test_hist_legacy
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
pandas/tests/plotting/test_hist_method.py::TestDataFramePlots::()::test_hist_df_legacy
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.
warnings.warn("The 'normed' kwarg is deprecated, and has been "
pandas/tests/plotting/test_hist_method.py::TestDataFramePlots::()::test_tight_layout
/Users/taugspurger/sandbox/pandas/pandas/tests/plotting/test_hist_method.py:248: UserWarning: To output multiple subplots, the figure containing the passed axes is being cleared
_check_plot_works(df.hist)
pandas/tests/plotting/test_hist_method.py::TestDataFrameGroupByPlots::()::test_grouped_hist_legacy
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.
warnings.warn("The 'normed' kwarg is deprecated, and has been "
pandas/tests/plotting/test_misc.py::TestSeriesPlots::()::test_autocorrelation_plot
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
pandas/tests/plotting/test_misc.py::TestDataFramePlots::()::test_andrews_curves
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
pandas/tests/plotting/test_misc.py::TestDataFramePlots::()::test_parallel_coordinates_with_sorted_labels
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/axes/_base.py:3124: UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=0, right=0
'left=%s, right=%s') % (left, right))
pandas/tests/plotting/test_misc.py::TestDataFramePlots::()::test_radviz
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/pyplot.py:984: UserWarning: Requested projection is different from current axis projection, creating new axis with requested projection.
return gcf().gca(**kwargs)
pandas/tests/scalar/timestamp/test_timezones.py::TestTimestampTZOperations::()::test_tz_localize_pushes_out_of_bounds
/Users/taugspurger/sandbox/pandas/pandas/tests/scalar/timestamp/test_timezones.py:32: RuntimeWarning: overflow encountered in long_scalars
Timestamp.min.tz_localize('Asia/Tokyo')
/Users/taugspurger/sandbox/pandas/pandas/tests/scalar/timestamp/test_timezones.py:39: RuntimeWarning: overflow encountered in long_scalars
Timestamp.max.tz_localize('US/Pacific')
pandas/tests/series/test_api.py::TestSeriesMisc::()::test_tab_complete_warning
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/IPython/core/interactiveshell.py:728: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
pandas/tests/plotting/test_series.py::TestSeriesPlots::()::test_hist_legacy
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
warnings.warn(message, mplDeprecation, stacklevel=1)
pandas/tests/plotting/test_frame.py::TestDataFramePlots::()::test_subplots_multiple_axes
/Users/taugspurger/sandbox/pandas/pandas/plotting/_tools.py:204: UserWarning: When passing multiple axes, layout keyword is ignored
"ignored", UserWarning)
pandas/tests/plotting/test_frame.py::TestDataFramePlots::()::test_hist_df
/Users/taugspurger/Envs/pandas/lib/python3.7/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.
warnings.warn("The 'normed' kwarg is deprecated, and has been "
pandas/tests/plotting/test_frame.py::TestDataFramePlots::()::test_line_colors
/Users/taugspurger/sandbox/pandas/pandas/plotting/_core.py:186: UserWarning: 'colors' is being deprecated. Please use 'color'instead of 'colors'
warnings.warn(("'colors' is being deprecated. Please use 'color'"
-- Docs: http://doc.pytest.org/en/latest/warnings.html
11 failed, 24364 passed, 758 skipped, 78 xfailed, 26 xpassed, 57 warnings in 465.39 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment