Skip to content

Commit 03adc86

Browse files
committed
TST: provide warning when using ExcelWriter/ExcelObject if from deprecated path
DOC: minor edits in 0.11.1 DOC: cookbook/io.rst doc updates TST: py3 issue on catching test warnings in test_parser_deprecated
1 parent d155623 commit 03adc86

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

doc/source/cookbook.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ Selection
3232

3333
The :ref:`indexing <indexing>` docs.
3434

35-
`Boolean Rows Indexing
35+
Indexing using both row labels and conditionals, see
36+
`here
3637
<http://stackoverflow.com/questions/14725068/pandas-using-row-labels-in-boolean-indexing>`__
37-
Indexing using both row labels and conditionals
3838

39-
`Using loc and iloc in selections
39+
Use loc for label-oriented slicing and iloc positional slicing, see
40+
`here
4041
<https://github.com/pydata/pandas/issues/2904>`__
41-
Use loc for label-oriented slicing and iloc positional slicing
4242

43-
`Extending a panel along the minor axis
43+
Extend a panel frame by transposing, adding a new dimension, and transposing back to the original dimensions, see
44+
`here
4445
<http://stackoverflow.com/questions/15364050/extending-a-pandas-panel-frame-along-the-minor-axis>`__
45-
Extend a panel frame by transposing, adding a new dimension, and transposing back to the original dimensions
4646

47-
`Boolean masking in a panel
47+
Mask a panel by using ``np.where`` and then reconstructing the panel with the new masked values
48+
`here
4849
<http://stackoverflow.com/questions/14650341/boolean-mask-in-pandas-panel>`__
49-
Mask a panel by using ``np.where`` and then reconstructing the panel with the new masked values
5050

51-
`Selecting via the complement
51+
Using ``~`` to take the complement of a boolean array, see
52+
`here
5253
<http://stackoverflow.com/questions/14986510/picking-out-elements-based-on-complement-of-indices-in-python-pandas>`__
53-
``~`` can be used to take the complement of a boolean array
5454

5555
`Efficiently creating columns using applymap
5656
<http://stackoverflow.com/questions/16575868/efficiently-creating-additional-columns-in-a-pandas-dataframe-using-map>`__

doc/source/io.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,9 +989,22 @@ module and use the same parsing code as the above to convert tabular data into
989989
a DataFrame. See the :ref:`cookbook<cookbook.excel>` for some
990990
advanced strategies
991991

992-
.. code-block:: python
992+
.. note::
993+
994+
The prior method of accessing Excel is now deprecated as of 0.11.1,
995+
this will work but will be removed in a future version.
996+
997+
.. code-block:: python
998+
999+
from pandas.io.parsers import ExcelFile
1000+
xls = ExcelFile('path_to_file.xls')
1001+
xls.parse('Sheet1', index_col=None, na_values=['NA'])
1002+
1003+
Replaced by
1004+
1005+
.. code-block:: python
9931006
994-
read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
1007+
read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
9951008
9961009
To read sheets from an Excel 2007 file, you can pass a filename with a ``.xlsx``
9971010
extension, in which case the ``openpyxl`` module will be used to read the file.

doc/source/v0.11.1.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,20 @@ API changes
9090
- IO api
9191

9292
- added top-level function ``read_excel`` to replace the following,
93-
however, the original API remains as well
93+
The original API is deprecated and will be removed in a future version
9494

9595
.. code-block:: python
9696

97+
from pandas.io.parsers import ExcelFile
9798
xls = ExcelFile('path_to_file.xls')
9899
xls.parse('Sheet1', index_col=None, na_values=['NA'])
99100

100101
With
101102

102103
.. code-block:: python
103104

104-
read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
105+
import pandas as pd
106+
pd.read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA'])
105107

106108
- added top-level function ``read_sql`` that is equivalent to the following
107109

pandas/io/parsers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,3 +1979,19 @@ def __init__(self, f, **kwds):
19791979

19801980
def _make_reader(self, f):
19811981
self.data = FixedWidthReader(f, self.colspecs, self.delimiter)
1982+
1983+
1984+
from pandas.io import excel
1985+
class ExcelWriter(excel.ExcelWriter):
1986+
def __init__(self, path):
1987+
from warnings import warn
1988+
warn("ExcelWriter can now be imported from: pandas.io.excel", FutureWarning)
1989+
super(ExcelWriter, self).__init__(path)
1990+
1991+
class ExcelFile(excel.ExcelFile):
1992+
def __init__(self, path_or_buf, kind=None, **kwds):
1993+
from warnings import warn
1994+
warn("ExcelFile can now be imported from: pandas.io.excel", FutureWarning)
1995+
super(ExcelFile, self).__init__(path_or_buf, kind=kind, **kwds)
1996+
1997+

pandas/io/tests/test_excel.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,23 @@ def roundtrip(df, header=True, parser_hdr=0):
854854
self.assertEqual(res.shape, (1, 2))
855855
self.assertTrue(res.ix[0, 0] is not np.nan)
856856

857+
def test_deprecated_from_parsers(self):
858+
859+
# since 0.11.1 changed the import path
860+
import warnings
861+
862+
with warnings.catch_warnings() as w:
863+
warnings.filterwarnings(action='ignore', category=FutureWarning)
864+
865+
_skip_if_no_xlrd()
866+
from pandas.io.parsers import ExcelFile as xf
867+
xf(self.xls1)
868+
869+
_skip_if_no_xlwt()
870+
with ensure_clean('test.xls') as path:
871+
from pandas.io.parsers import ExcelWriter as xw
872+
xw(path)
873+
857874
if __name__ == '__main__':
858875
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
859876
exit=False)

0 commit comments

Comments
 (0)