Skip to content

Commit

Permalink
DEPR: Remove xlwt (pandas-dev#49296)
Browse files Browse the repository at this point in the history
* DEPR: Remove xlwt

* Remove another ref to option

* Adjust tests

* Just remove xls benchmark

* Fix some tests
  • Loading branch information
mroeschke authored Oct 27, 2022
1 parent 05fb08e commit bcb8346
Show file tree
Hide file tree
Showing 31 changed files with 35 additions and 538 deletions.
1 change: 0 additions & 1 deletion asv_bench/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"openpyxl": [],
"xlsxwriter": [],
"xlrd": [],
"xlwt": [],
"odfpy": [],
"jinja2": [],
},
Expand Down
14 changes: 4 additions & 10 deletions asv_bench/benchmarks/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _generate_dataframe():

class WriteExcel:

params = ["openpyxl", "xlsxwriter", "xlwt"]
params = ["openpyxl", "xlsxwriter"]
param_names = ["engine"]

def setup(self, engine):
Expand Down Expand Up @@ -68,10 +68,9 @@ def time_write_excel_style(self, engine):

class ReadExcel:

params = ["xlrd", "openpyxl", "odf"]
params = ["openpyxl", "odf"]
param_names = ["engine"]
fname_excel = "spreadsheet.xlsx"
fname_excel_xls = "spreadsheet.xls"
fname_odf = "spreadsheet.ods"

def _create_odf(self):
Expand All @@ -92,13 +91,10 @@ def setup_cache(self):
self.df = _generate_dataframe()

self.df.to_excel(self.fname_excel, sheet_name="Sheet1")
self.df.to_excel(self.fname_excel_xls, sheet_name="Sheet1")
self._create_odf()

def time_read_excel(self, engine):
if engine == "xlrd":
fname = self.fname_excel_xls
elif engine == "odf":
if engine == "odf":
fname = self.fname_odf
else:
fname = self.fname_excel
Expand All @@ -107,9 +103,7 @@ def time_read_excel(self, engine):

class ReadExcelNRows(ReadExcel):
def time_read_excel(self, engine):
if engine == "xlrd":
fname = self.fname_excel_xls
elif engine == "odf":
if engine == "odf":
fname = self.fname_odf
else:
fname = self.fname_excel
Expand Down
2 changes: 1 addition & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import pandas
blocklist = {'bs4', 'gcsfs', 'html5lib', 'http', 'ipython', 'jinja2', 'hypothesis',
'lxml', 'matplotlib', 'openpyxl', 'py', 'pytest', 's3fs', 'scipy',
'tables', 'urllib.request', 'xlrd', 'xlsxwriter', 'xlwt'}
'tables', 'urllib.request', 'xlrd', 'xlsxwriter'}
# GH#28227 for some of these check for top-level modules, while others are
# more specific (e.g. urllib.request)
Expand Down
1 change: 0 additions & 1 deletion ci/deps/actions-310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard
1 change: 0 additions & 1 deletion ci/deps/actions-38-downstream_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard

# downstream packages
Expand Down
1 change: 0 additions & 1 deletion ci/deps/actions-38-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ dependencies:
- xarray=0.19.0
- xlrd=2.0.1
- xlsxwriter=1.4.3
- xlwt=1.3.0
- zstandard=0.15.2
1 change: 0 additions & 1 deletion ci/deps/actions-38.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard
1 change: 0 additions & 1 deletion ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard
1 change: 0 additions & 1 deletion ci/deps/circle-38-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard
1 change: 0 additions & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ Can be managed as optional_extra with ``pandas[excel]``.
Dependency Minimum Version optional_extra Notes
========================= ================== =============== =============================================================
xlrd 2.0.1 excel Reading Excel
xlwt 1.3.0 excel Writing Excel
xlsxwriter 1.4.3 excel Writing Excel
openpyxl 3.0.7 excel Reading / writing for xlsx files
pyxlsb 1.0.8 excel Reading for xlsb files
Expand Down
21 changes: 2 additions & 19 deletions doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3466,8 +3466,6 @@ See the :ref:`cookbook<cookbook.excel>` for some advanced strategies.

.. warning::

The `xlwt <https://xlwt.readthedocs.io/en/latest/>`__ package for writing old-style ``.xls``
excel files is no longer maintained.
The `xlrd <https://xlrd.readthedocs.io/en/latest/>`__ package is now only for reading
old-style ``.xls`` files.

Expand All @@ -3481,12 +3479,6 @@ See the :ref:`cookbook<cookbook.excel>` for some advanced strategies.
**Please do not report issues when using ``xlrd`` to read ``.xlsx`` files.**
This is no longer supported, switch to using ``openpyxl`` instead.

Attempting to use the ``xlwt`` engine will raise a ``FutureWarning``
unless the option :attr:`io.excel.xls.writer` is set to ``"xlwt"``.
While this option is now deprecated and will also raise a ``FutureWarning``,
it can be globally set and the warning suppressed. Users are recommended to
write ``.xlsx`` files using the ``openpyxl`` engine instead.

.. _io.excel_reader:

Reading Excel files
Expand Down Expand Up @@ -3788,7 +3780,7 @@ written. For example:
df.to_excel("path_to_file.xlsx", sheet_name="Sheet1")
Files with a ``.xls`` extension will be written using ``xlwt`` and those with a
Files with a
``.xlsx`` extension will be written using ``xlsxwriter`` (if available) or
``openpyxl``.

Expand Down Expand Up @@ -3849,35 +3841,26 @@ pandas supports writing Excel files to buffer-like objects such as ``StringIO``
Excel writer engines
''''''''''''''''''''

.. deprecated:: 1.2.0

As the `xlwt <https://pypi.org/project/xlwt/>`__ package is no longer
maintained, the ``xlwt`` engine will be removed from a future version
of pandas. This is the only engine in pandas that supports writing to
``.xls`` files.

pandas chooses an Excel writer via two methods:

1. the ``engine`` keyword argument
2. the filename extension (via the default specified in config options)

By default, pandas uses the `XlsxWriter`_ for ``.xlsx``, `openpyxl`_
for ``.xlsm``, and `xlwt`_ for ``.xls`` files. If you have multiple
for ``.xlsm``. If you have multiple
engines installed, you can set the default engine through :ref:`setting the
config options <options>` ``io.excel.xlsx.writer`` and
``io.excel.xls.writer``. pandas will fall back on `openpyxl`_ for ``.xlsx``
files if `Xlsxwriter`_ is not available.

.. _XlsxWriter: https://xlsxwriter.readthedocs.io
.. _openpyxl: https://openpyxl.readthedocs.io/
.. _xlwt: http://www.python-excel.org

To specify which writer you want to use, you can pass an engine keyword
argument to ``to_excel`` and to ``ExcelWriter``. The built-in engines are:

* ``openpyxl``: version 2.4 or higher is required
* ``xlsxwriter``
* ``xlwt``

.. code-block:: python
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ dependencies:
- xarray
- xlrd
- xlsxwriter
- xlwt
- zstandard

# downstream packages
Expand Down
1 change: 0 additions & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"tabulate": "0.8.9",
"xarray": "0.19.0",
"xlrd": "2.0.1",
"xlwt": "1.3.0",
"xlsxwriter": "1.4.3",
"zstandard": "0.15.2",
"tzdata": "2022.1",
Expand Down
16 changes: 0 additions & 16 deletions pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,27 +624,11 @@ def use_inf_as_na_cb(key) -> None:
auto, {others}.
"""

_xls_options = ["xlwt"]
_xlsm_options = ["openpyxl"]
_xlsx_options = ["openpyxl", "xlsxwriter"]
_ods_options = ["odf"]


with cf.config_prefix("io.excel.xls"):
cf.register_option(
"writer",
"auto",
writer_engine_doc.format(ext="xls", others=", ".join(_xls_options)),
validator=str,
)
cf.deprecate_option(
"io.excel.xls.writer",
msg="As the xlwt package is no longer maintained, the xlwt engine will be "
"removed in a future version of pandas. This is the only engine in pandas that "
"supports writing in the xls format. Install openpyxl and write to an "
"xlsx file instead.",
)

with cf.config_prefix("io.excel.xlsm"):
cf.register_option(
"writer",
Expand Down
8 changes: 1 addition & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2260,15 +2260,9 @@ def to_excel(
Upper left cell column to dump data frame.
engine : str, optional
Write engine to use, 'openpyxl' or 'xlsxwriter'. You can also set this
via the options ``io.excel.xlsx.writer``, ``io.excel.xls.writer``, and
via the options ``io.excel.xlsx.writer`` or
``io.excel.xlsm.writer``.
.. deprecated:: 1.2.0
As the `xlwt <https://pypi.org/project/xlwt/>`__ package is no longer
maintained, the ``xlwt`` engine will be removed in a future version
of pandas.
merge_cells : bool, default True
Write MultiIndex and Hierarchical Rows as merged cells.
encoding : str, optional
Expand Down
5 changes: 0 additions & 5 deletions pandas/io/excel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
from pandas.io.excel._openpyxl import OpenpyxlWriter as _OpenpyxlWriter
from pandas.io.excel._util import register_writer
from pandas.io.excel._xlsxwriter import XlsxWriter as _XlsxWriter
from pandas.io.excel._xlwt import XlwtWriter as _XlwtWriter

__all__ = ["read_excel", "ExcelWriter", "ExcelFile"]


register_writer(_OpenpyxlWriter)


register_writer(_XlwtWriter)


register_writer(_XlsxWriter)


Expand Down
27 changes: 0 additions & 27 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ class ExcelWriter(metaclass=abc.ABCMeta):
Default is to use:
* `xlwt <https://pypi.org/project/xlwt/>`__ for xls files
* `xlsxwriter <https://pypi.org/project/XlsxWriter/>`__ for xlsx files if xlsxwriter
is installed otherwise `openpyxl <https://pypi.org/project/openpyxl/>`__
* `odswriter <https://pypi.org/project/odswriter/>`__ for ods files
Expand All @@ -911,13 +910,6 @@ class ExcelWriter(metaclass=abc.ABCMeta):
Engine to use for writing. If None, defaults to
``io.excel.<extension>.writer``. NOTE: can only be passed as a keyword
argument.
.. deprecated:: 1.2.0
As the `xlwt <https://pypi.org/project/xlwt/>`__ package is no longer
maintained, the ``xlwt`` engine will be removed in a future
version of pandas.
date_format : str, default None
Format string for dates written into Excel files (e.g. 'YYYY-MM-DD').
datetime_format : str, default None
Expand Down Expand Up @@ -1127,25 +1119,6 @@ def __new__(
except KeyError as err:
raise ValueError(f"No engine for filetype: '{ext}'") from err

if engine == "xlwt":
xls_config_engine = config.get_option(
"io.excel.xls.writer", silent=True
)
# Don't warn a 2nd time if user has changed the default engine for xls
if xls_config_engine != "xlwt":
warnings.warn(
"As the xlwt package is no longer maintained, the xlwt "
"engine will be removed in a future version of pandas. "
"This is the only engine in pandas that supports writing "
"in the xls format. Install openpyxl and write to an xlsx "
"file instead. You can set the option io.excel.xls.writer "
"to 'xlwt' to silence this warning. While this option is "
"deprecated and will also raise a warning, it can "
"be globally set and the warning suppressed.",
FutureWarning,
stacklevel=find_stack_level(),
)

# for mypy
assert engine is not None
cls = get_writer(engine)
Expand Down
1 change: 0 additions & 1 deletion pandas/io/excel/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def get_default_engine(ext: str, mode: Literal["reader", "writer"] = "reader") -
"xlsx": "openpyxl",
"xlsm": "openpyxl",
"xlsb": "pyxlsb",
"xls": "xlwt",
"ods": "odf",
}
assert mode in ["reader", "writer"]
Expand Down
Loading

0 comments on commit bcb8346

Please sign in to comment.