Skip to content

Commit

Permalink
Merge pull request #1 from dimastbk/issue-50395-dima
Browse files Browse the repository at this point in the history
calamite -> calamine, updated some tests for calamine
  • Loading branch information
kostyafarber authored Jan 22, 2023
2 parents 038133e + 52c2cbd commit 2dc5e02
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ci/deps/actions-38-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ dependencies:

- pip:
- pyqt5==5.15.1
- python-calamine==0.0.5
- python-calamine==0.0.6
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Other enhancements
- Improved error message in :func:`to_datetime` for non-ISO8601 formats, informing users about the position of the first error (:issue:`50361`)
- Improved error message when trying to align :class:`DataFrame` objects (for example, in :func:`DataFrame.compare`) to clarify that "identically labelled" refers to both index and columns (:issue:`50083`)
- Performance improvement in :func:`to_datetime` when format is given or can be inferred (:issue:`50465`)
- Added ``calamite`` as an engine to ``read_excel`` (:issue: ``50395``)
- Added ``calamine`` as an engine to ``read_excel`` (:issue: ``50395``)
- Added :meth:`DatetimeIndex.as_unit` and :meth:`TimedeltaIndex.as_unit` to convert to different resolutions; supported resolutions are "s", "ms", "us", and "ns" (:issue:`50616`)

.. ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"pyarrow": "6.0.0",
"pyreadstat": "1.1.2",
"pytest": "7.0.0",
"python-calamine": "0.0.6",
"pyxlsb": "1.0.8",
"s3fs": "2021.08.0",
"scipy": "1.7.1",
Expand All @@ -48,7 +49,6 @@
"tzdata": "2022.1",
"qtpy": "2.2.0",
"pyqt5": "5.15.1",
"python-calamine": "0.0.5",
}

# A mapping from import name to package name (on PyPI) for packages where
Expand All @@ -62,6 +62,7 @@
"lxml.etree": "lxml",
"odf": "odfpy",
"pandas_gbq": "pandas-gbq",
"python_calamine": "python-calamine",
"snappy": "python-snappy",
"sqlalchemy": "SQLAlchemy",
"tables": "pytables",
Expand Down
9 changes: 7 additions & 2 deletions pandas/io/excel/_calaminereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tempfile import NamedTemporaryFile
from typing import Any

from pandas.compat._optional import import_optional_dependency
from pandas._typing import StorageOptions

from pandas.io.excel._base import (
BaseExcelReader,
Expand All @@ -23,7 +23,12 @@ class __calamine__:
class CalamineExcelReader(BaseExcelReader):
book: str
_sheet_names: list[str] | None = None
import_optional_dependency("python_calamine")

def __init__(
self, filepath_or_buffer, storage_options: StorageOptions = None
) -> None:
import_optional_dependency("python_calamine")
super().__init__(filepath_or_buffer, storage_options=storage_options)

@property
def _workbook_class(self) -> type[__calamine__]:
Expand Down
21 changes: 15 additions & 6 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
),
pytest.param("pyxlsb", marks=td.skip_if_no("pyxlsb")),
pytest.param("odf", marks=td.skip_if_no("odf")),
pytest.param("calamine", marks=td.skip_if_no("calamine")),
pytest.param("calamine", marks=td.skip_if_no("python_calamine")),
]


Expand All @@ -66,11 +66,11 @@ def _is_valid_engine_ext_pair(engine, read_ext: str) -> bool:
return False
if engine == "odf" and read_ext != ".ods":
return False
if read_ext == ".ods" and engine != "odf":
if read_ext == ".ods" and engine not in {"odf", "calamine"}:
return False
if engine == "pyxlsb" and read_ext != ".xlsb":
return False
if read_ext == ".xlsb" and engine != "pyxlsb":
if read_ext == ".xlsb" and engine not in {"pyxlsb", "calamine"}:
return False
if engine == "xlrd" and read_ext != ".xls":
return False
Expand Down Expand Up @@ -834,6 +834,11 @@ def test_corrupt_bytes_raises(self, engine):
"Unsupported format, or corrupt file: Expected BOF "
"record; found b'foo'"
)
elif engine == "calamine":
import python_calamine

error = python_calamine._python_calamine.CalamineError
msg = "Cannot detect file format"
else:
error = BadZipFile
msg = "File is not a zip file"
Expand Down Expand Up @@ -1374,7 +1379,7 @@ def test_trailing_blanks(self, read_ext):

def test_ignore_chartsheets_by_str(self, request, engine, read_ext):
# GH 41448
if engine == "odf":
if read_ext == ".ods":
pytest.skip("chartsheets do not exist in the ODF format")
if engine == "pyxlsb":
request.node.add_marker(
Expand All @@ -1387,7 +1392,7 @@ def test_ignore_chartsheets_by_str(self, request, engine, read_ext):

def test_ignore_chartsheets_by_int(self, request, engine, read_ext):
# GH 41448
if engine == "odf":
if read_ext == ".ods":
pytest.skip("chartsheets do not exist in the ODF format")
if engine == "pyxlsb":
request.node.add_marker(
Expand Down Expand Up @@ -1656,7 +1661,7 @@ def test_engine_invalid_option(self, read_ext):

def test_ignore_chartsheets(self, request, engine, read_ext):
# GH 41448
if engine == "odf":
if read_ext == ".ods":
pytest.skip("chartsheets do not exist in the ODF format")
if engine == "pyxlsb":
request.node.add_marker(
Expand All @@ -1676,6 +1681,10 @@ def test_corrupt_files_closed(self, engine, read_ext):
import xlrd

errors = (BadZipFile, xlrd.biffh.XLRDError)
elif engine == "calamine":
import python_calamine

errors = (python_calamine._python_calamine.CalamineError,)

with tm.ensure_clean(f"corrupt{read_ext}") as file:
Path(file).write_text("corrupt")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ all = ['beautifulsoup4>=4.9.3',
'pytest>=7.0.0',
'pytest-xdist>=2.2.0',
'pytest-asyncio>=0.17.0',
'python-calamine>=0.0.5',
'python-calamine>=0.0.6',
'python-snappy>=0.6.0',
'pyxlsb>=1.0.8',
'qtpy>=2.2.0',
Expand Down

0 comments on commit 2dc5e02

Please sign in to comment.