From 8df59ed0d5c0889ecf34d29a1933cc66f00ec46b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:25:33 -0800 Subject: [PATCH 01/11] CI/TST: Check for PytestUnraisableExceptionWarning instead of psutil for open resouces for tests --- ci/deps/actions-310.yaml | 1 - ci/deps/actions-311.yaml | 1 - ci/deps/actions-38-downstream_compat.yaml | 1 - ci/deps/actions-38-minimum_versions.yaml | 1 - ci/deps/actions-38.yaml | 1 - ci/deps/actions-39.yaml | 1 - ci/deps/circle-38-arm64.yaml | 1 - environment.yml | 1 - pandas/io/excel/_base.py | 8 ---- pandas/tests/frame/test_api.py | 2 - pandas/tests/io/excel/conftest.py | 26 ----------- pandas/tests/io/excel/test_readers.py | 2 - pandas/tests/io/formats/test_format.py | 2 - .../io/parser/common/test_file_buffer_url.py | 18 ++------ .../io/parser/common/test_read_errors.py | 2 - .../tests/resample/test_resampler_grouper.py | 2 - pandas/util/_test_decorators.py | 44 +------------------ pyproject.toml | 3 ++ requirements-dev.txt | 1 - 19 files changed, 7 insertions(+), 111 deletions(-) diff --git a/ci/deps/actions-310.yaml b/ci/deps/actions-310.yaml index e442beda102eb..e2bfe6e57d216 100644 --- a/ci/deps/actions-310.yaml +++ b/ci/deps/actions-310.yaml @@ -12,7 +12,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/actions-311.yaml b/ci/deps/actions-311.yaml index 85103276fa6a6..237924b5c6f0b 100644 --- a/ci/deps/actions-311.yaml +++ b/ci/deps/actions-311.yaml @@ -12,7 +12,6 @@ dependencies: - pytest>=7.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/actions-38-downstream_compat.yaml b/ci/deps/actions-38-downstream_compat.yaml index e313d4efbf8a7..9b62b25a15740 100644 --- a/ci/deps/actions-38-downstream_compat.yaml +++ b/ci/deps/actions-38-downstream_compat.yaml @@ -13,7 +13,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/actions-38-minimum_versions.yaml b/ci/deps/actions-38-minimum_versions.yaml index 7652b6347ad4f..f3ff36a1b2ada 100644 --- a/ci/deps/actions-38-minimum_versions.yaml +++ b/ci/deps/actions-38-minimum_versions.yaml @@ -14,7 +14,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/actions-38.yaml b/ci/deps/actions-38.yaml index 233cd651a85af..95bab9897ac63 100644 --- a/ci/deps/actions-38.yaml +++ b/ci/deps/actions-38.yaml @@ -12,7 +12,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/actions-39.yaml b/ci/deps/actions-39.yaml index 0a56337dd3bbd..9d95e28ae9fb6 100644 --- a/ci/deps/actions-39.yaml +++ b/ci/deps/actions-39.yaml @@ -12,7 +12,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/ci/deps/circle-38-arm64.yaml b/ci/deps/circle-38-arm64.yaml index 40cfe7b605278..1548eb3d4929d 100644 --- a/ci/deps/circle-38-arm64.yaml +++ b/ci/deps/circle-38-arm64.yaml @@ -12,7 +12,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - boto3 diff --git a/environment.yml b/environment.yml index 04ded62262483..41c93de50bff3 100644 --- a/environment.yml +++ b/environment.yml @@ -14,7 +14,6 @@ dependencies: - pytest>=7.0.0 - pytest-cov - pytest-xdist>=2.2.0 - - psutil - pytest-asyncio>=0.17 - coverage diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 4463dc5d672a9..99ce103199b34 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1617,11 +1617,3 @@ def __exit__( traceback: TracebackType | None, ) -> None: self.close() - - def __del__(self) -> None: - # Ensure we don't leak file descriptors, but put in try/except in case - # attributes are already deleted - try: - self.close() - except AttributeError: - pass diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 4ffb4b6b355b6..e5787a7f16a35 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -7,7 +7,6 @@ from pandas._config.config import option_context -import pandas.util._test_decorators as td from pandas.util._test_decorators import ( async_mark, skip_if_no, @@ -293,7 +292,6 @@ def _check_f(base, f): _check_f(d.copy(), f) @async_mark() - @td.check_file_leaks async def test_tab_complete_warning(self, ip, frame_or_series): # GH 16409 pytest.importorskip("IPython", minversion="6.0.0") diff --git a/pandas/tests/io/excel/conftest.py b/pandas/tests/io/excel/conftest.py index 4ce06c01892d9..15ff52d5bea48 100644 --- a/pandas/tests/io/excel/conftest.py +++ b/pandas/tests/io/excel/conftest.py @@ -1,8 +1,5 @@ import pytest -from pandas.compat import is_platform_windows -import pandas.util._test_decorators as td - import pandas._testing as tm from pandas.io.parsers import read_csv @@ -42,26 +39,3 @@ def read_ext(request): Valid extensions for reading Excel files. """ return request.param - - -# Checking for file leaks can hang on Windows CI -@pytest.fixture(autouse=not is_platform_windows()) -def check_for_file_leaks(): - """ - Fixture to run around every test to ensure that we are not leaking files. - - See also - -------- - _test_decorators.check_file_leaks - """ - # GH#30162 - psutil = td.safe_import("psutil") - if not psutil: - yield - - else: - proc = psutil.Process() - flist = proc.open_files() - yield - flist2 = proc.open_files() - assert flist == flist2 diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 5fdd0e4311d88..b36f3fcee16ca 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -909,7 +909,6 @@ def test_read_from_pathlib_path(self, read_ext): tm.assert_frame_equal(expected, actual) @td.skip_if_no("py.path") - @td.check_file_leaks def test_read_from_py_localpath(self, read_ext): # GH12655 from py.path import local as LocalPath @@ -922,7 +921,6 @@ def test_read_from_py_localpath(self, read_ext): tm.assert_frame_equal(expected, actual) - @td.check_file_leaks def test_close_from_py_localpath(self, read_ext): # GH31467 str_path = os.path.join("test1" + read_ext) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index af117af0c8d3d..fae29c124df71 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -26,7 +26,6 @@ IS64, is_platform_windows, ) -import pandas.util._test_decorators as td import pandas as pd from pandas import ( @@ -3400,7 +3399,6 @@ def test_format_percentiles_integer_idx(): assert result == expected -@td.check_file_leaks def test_repr_html_ipython_config(ip): code = textwrap.dedent( """\ diff --git a/pandas/tests/io/parser/common/test_file_buffer_url.py b/pandas/tests/io/parser/common/test_file_buffer_url.py index 3f1d013c5471d..c11a59a8b4660 100644 --- a/pandas/tests/io/parser/common/test_file_buffer_url.py +++ b/pandas/tests/io/parser/common/test_file_buffer_url.py @@ -13,7 +13,6 @@ import pytest -from pandas.compat import is_ci_environment from pandas.errors import ( EmptyDataError, ParserError, @@ -404,25 +403,14 @@ def test_context_manageri_user_provided(all_parsers, datapath): assert not reader.handles.handle.closed -def test_file_descriptor_leak(all_parsers, using_copy_on_write, request): +def test_file_descriptor_leak(all_parsers, using_copy_on_write): # GH 31488 - if using_copy_on_write and is_ci_environment(): - mark = pytest.mark.xfail( - reason="2023-02-12 frequent-but-flaky failures", strict=False - ) - request.node.add_marker(mark) - parser = all_parsers with tm.ensure_clean() as path: - - def test(): - with pytest.raises(EmptyDataError, match="No columns to parse from file"): - parser.read_csv(path) - - td.check_file_leaks(test)() + with pytest.raises(EmptyDataError, match="No columns to parse from file"): + parser.read_csv(path) -@td.check_file_leaks def test_memory_map(all_parsers, csv_dir_path): mmap_file = os.path.join(csv_dir_path, "test_mmap.csv") parser = all_parsers diff --git a/pandas/tests/io/parser/common/test_read_errors.py b/pandas/tests/io/parser/common/test_read_errors.py index f5a7eb4ccd2fa..817daad9849c0 100644 --- a/pandas/tests/io/parser/common/test_read_errors.py +++ b/pandas/tests/io/parser/common/test_read_errors.py @@ -17,7 +17,6 @@ EmptyDataError, ParserError, ) -import pandas.util._test_decorators as td from pandas import DataFrame import pandas._testing as tm @@ -204,7 +203,6 @@ def test_null_byte_char(request, all_parsers): parser.read_csv(StringIO(data), names=names) -@td.check_file_leaks def test_open_file(request, all_parsers): # GH 39024 parser = all_parsers diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 2aa2b272547bc..425eef69c52ae 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -3,7 +3,6 @@ import numpy as np import pytest -import pandas.util._test_decorators as td from pandas.util._test_decorators import async_mark import pandas as pd @@ -24,7 +23,6 @@ @async_mark() -@td.check_file_leaks async def test_tab_complete_ipython6_warning(ip): from IPython.core.completer import provisionalcompleter diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index de100dba8144d..dfe48d994cb0e 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -25,13 +25,8 @@ def test_foo(): """ from __future__ import annotations -from contextlib import contextmanager -import gc import locale -from typing import ( - Callable, - Generator, -) +from typing import Callable import numpy as np import pytest @@ -233,43 +228,6 @@ def documented_fixture(fixture): return documented_fixture -def check_file_leaks(func) -> Callable: - """ - Decorate a test function to check that we are not leaking file descriptors. - """ - with file_leak_context(): - return func - - -@contextmanager -def file_leak_context() -> Generator[None, None, None]: - """ - ContextManager analogue to check_file_leaks. - """ - psutil = safe_import("psutil") - if not psutil or is_platform_windows(): - # Checking for file leaks can hang on Windows CI - yield - else: - proc = psutil.Process() - flist = proc.open_files() - conns = proc.connections() - - try: - yield - finally: - gc.collect() - flist2 = proc.open_files() - # on some builds open_files includes file position, which we _dont_ - # expect to remain unchanged, so we need to compare excluding that - flist_ex = [(x.path, x.fd) for x in flist] - flist2_ex = [(x.path, x.fd) for x in flist2] - assert set(flist2_ex) <= set(flist_ex), (flist2, flist) - - conns2 = proc.connections() - assert conns2 == conns, (conns2, conns) - - def async_mark(): try: import_optional_dependency("pytest_asyncio") diff --git a/pyproject.toml b/pyproject.toml index 511cc6a4d46eb..a5368fbad1cf3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -395,6 +395,9 @@ doctest_optionflags = [ "ELLIPSIS", ] filterwarnings = [ + # Raise on ResourceWarnings, especially indicative of open files + # https://github.com/pytest-dev/pytest/issues/9825 + "error::pytest.PytestUnraisableExceptionWarning", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", "ignore:.*urllib3:DeprecationWarning:botocore", diff --git a/requirements-dev.txt b/requirements-dev.txt index 044052f4624f5..1ad81472b1779 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,6 @@ cython==0.29.32 pytest>=7.0.0 pytest-cov pytest-xdist>=2.2.0 -psutil pytest-asyncio>=0.17 coverage python-dateutil From f903f62b14ad668f81ed37f8e9732eb5efc891c7 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 16 Feb 2023 15:52:56 -0800 Subject: [PATCH 02/11] Make ResourceWarning also error --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a5368fbad1cf3..7d1ad5577adf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -397,6 +397,7 @@ doctest_optionflags = [ filterwarnings = [ # Raise on ResourceWarnings, especially indicative of open files # https://github.com/pytest-dev/pytest/issues/9825 + "error::ResourceWarning", "error::pytest.PytestUnraisableExceptionWarning", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", From 5c24bdd6df62c67f078e22ef7cdc8c9a42f296b4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:05:55 -0800 Subject: [PATCH 03/11] Fix ExcelWriter not clossing files during instantiation --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/io/excel/_base.py | 22 +++++++++++----------- pandas/io/excel/_odswriter.py | 6 +++--- pandas/io/excel/_openpyxl.py | 12 ++++++++++-- pandas/tests/io/sas/test_xport.py | 14 +++----------- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 78422ec686da8..f692696c985d0 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -1330,6 +1330,7 @@ I/O - Bug in :meth:`DataFrame.to_html` with ``na_rep`` set when the :class:`DataFrame` contains non-scalar data (:issue:`47103`) - Bug in :func:`read_xml` where file-like objects failed when iterparse is used (:issue:`50641`) - Bug in :func:`read_xml` ignored repeated elements when iterparse is used (:issue:`51183`) +- Bug in :class:`ExcelWriter` leaving file handles open if an exception occurred during instantiation (:issue:`51443`) Period ^^^^^^ diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 99ce103199b34..7d7b40efb86ec 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1223,6 +1223,17 @@ def __init__( # the excel backend first read the existing file and then write any data to it mode = mode.replace("a", "r+") + if if_sheet_exists not in (None, "error", "new", "replace", "overlay"): + raise ValueError( + f"'{if_sheet_exists}' is not valid for if_sheet_exists. " + "Valid options are 'error', 'new', 'replace' and 'overlay'." + ) + if if_sheet_exists and "r+" not in mode: + raise ValueError("if_sheet_exists is only valid in append mode (mode='a')") + if if_sheet_exists is None: + if_sheet_exists = "error" + self._if_sheet_exists = if_sheet_exists + # cast ExcelWriter to avoid adding 'if self._handles is not None' self._handles = IOHandles( cast(IO[bytes], path), compression={"compression": None} @@ -1244,17 +1255,6 @@ def __init__( self._mode = mode - if if_sheet_exists not in (None, "error", "new", "replace", "overlay"): - raise ValueError( - f"'{if_sheet_exists}' is not valid for if_sheet_exists. " - "Valid options are 'error', 'new', 'replace' and 'overlay'." - ) - if if_sheet_exists and "r+" not in mode: - raise ValueError("if_sheet_exists is only valid in append mode (mode='a')") - if if_sheet_exists is None: - if_sheet_exists = "error" - self._if_sheet_exists = if_sheet_exists - @property def date_format(self) -> str: """ diff --git a/pandas/io/excel/_odswriter.py b/pandas/io/excel/_odswriter.py index 5ea3d8d3e43f4..6f1d62111e5b4 100644 --- a/pandas/io/excel/_odswriter.py +++ b/pandas/io/excel/_odswriter.py @@ -48,6 +48,9 @@ def __init__( if mode == "a": raise ValueError("Append mode is not supported with odf!") + engine_kwargs = combine_kwargs(engine_kwargs, kwargs) + self._book = OpenDocumentSpreadsheet(**engine_kwargs) + super().__init__( path, mode=mode, @@ -56,9 +59,6 @@ def __init__( engine_kwargs=engine_kwargs, ) - engine_kwargs = combine_kwargs(engine_kwargs, kwargs) - - self._book = OpenDocumentSpreadsheet(**engine_kwargs) self._style_dict: dict[str, str] = {} @property diff --git a/pandas/io/excel/_openpyxl.py b/pandas/io/excel/_openpyxl.py index 69ddadc58f10b..594813fe0c1ac 100644 --- a/pandas/io/excel/_openpyxl.py +++ b/pandas/io/excel/_openpyxl.py @@ -70,11 +70,19 @@ def __init__( if "r+" in self._mode: # Load from existing workbook from openpyxl import load_workbook - self._book = load_workbook(self._handles.handle, **engine_kwargs) + try: + self._book = load_workbook(self._handles.handle, **engine_kwargs) + except TypeError: + self._handles.handle.close() + raise self._handles.handle.seek(0) else: # Create workbook object with default optimized_write=True. - self._book = Workbook(**engine_kwargs) + try: + self._book = Workbook(**engine_kwargs) + except TypeError: + self._handles.handle.close() + raise if self.book.worksheets: self.book.remove(self.book.worksheets[0]) diff --git a/pandas/tests/io/sas/test_xport.py b/pandas/tests/io/sas/test_xport.py index 2046427deeaf0..766c9c37d55b9 100644 --- a/pandas/tests/io/sas/test_xport.py +++ b/pandas/tests/io/sas/test_xport.py @@ -1,8 +1,6 @@ import numpy as np import pytest -import pandas.util._test_decorators as td - import pandas as pd import pandas._testing as tm @@ -21,11 +19,6 @@ def numeric_as_float(data): class TestXport: - @pytest.fixture(autouse=True) - def setup_method(self): - with td.file_leak_context(): - yield - @pytest.fixture def file01(self, datapath): return datapath("io", "sas", "data", "DEMO_G.xpt") @@ -138,10 +131,9 @@ def test2_binary(self, file02): numeric_as_float(data_csv) with open(file02, "rb") as fd: - with td.file_leak_context(): - # GH#35693 ensure that if we pass an open file, we - # dont incorrectly close it in read_sas - data = read_sas(fd, format="xport") + # GH#35693 ensure that if we pass an open file, we + # dont incorrectly close it in read_sas + data = read_sas(fd, format="xport") tm.assert_frame_equal(data, data_csv) From a04626776e8c8883b5c1d2ac9534c801cb5b16f8 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Thu, 16 Feb 2023 20:16:52 -0800 Subject: [PATCH 04/11] Ignore asyncio ResourceWarnings --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7d1ad5577adf0..58c9856af309d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -395,9 +395,9 @@ doctest_optionflags = [ "ELLIPSIS", ] filterwarnings = [ - # Raise on ResourceWarnings, especially indicative of open files - # https://github.com/pytest-dev/pytest/issues/9825 "error::ResourceWarning", + # Ignore ResourceWarnings from asyncio (other libraries) + "ignore::ResourceWarning:asyncio" "error::pytest.PytestUnraisableExceptionWarning", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", From edaf9db535d16a2537200f5fd34b08cae1822a12 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:13:37 -0800 Subject: [PATCH 05/11] Forgot comma --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 58c9856af309d..43883379b83da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -397,7 +397,7 @@ doctest_optionflags = [ filterwarnings = [ "error::ResourceWarning", # Ignore ResourceWarnings from asyncio (other libraries) - "ignore::ResourceWarning:asyncio" + "ignore::ResourceWarning:asyncio", "error::pytest.PytestUnraisableExceptionWarning", # Will be fixed in numba 0.56: https://github.com/numba/numba/issues/7758 "ignore:`np.MachAr` is deprecated:DeprecationWarning:numba", From d5d269be358d720ef3fa6c2a460406f691abd355 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Fri, 17 Feb 2023 13:58:12 -0800 Subject: [PATCH 06/11] Ignore socketwarnings --- pandas/_testing/_warnings.py | 17 ----------------- pyproject.toml | 1 + 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 69ef57d9f450d..0d1076f235b1d 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -5,7 +5,6 @@ nullcontext, ) import re -import sys from typing import ( Generator, Literal, @@ -164,22 +163,6 @@ def _assert_caught_no_extra_warnings( for actual_warning in caught_warnings: if _is_unexpected_warning(actual_warning, expected_warning): - # GH#38630 pytest.filterwarnings does not suppress these. - if actual_warning.category == ResourceWarning: - # GH 44732: Don't make the CI flaky by filtering SSL-related - # ResourceWarning from dependencies - unclosed_ssl = ( - "unclosed transport Date: Fri, 17 Feb 2023 16:38:58 -0800 Subject: [PATCH 07/11] More permissive mesage match --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 58923eb8328c7..f56210b7d590c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -396,7 +396,7 @@ doctest_optionflags = [ ] filterwarnings = [ "error::ResourceWarning", - "ignore:unclosed Date: Fri, 17 Feb 2023 16:44:07 -0800 Subject: [PATCH 08/11] Ignore tzlocal specific 32 bit error --- pandas/tests/scalar/timestamp/test_timestamp.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 855b8d52aa84d..4cc45acc1b3a7 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -10,7 +10,10 @@ import time import unicodedata -from dateutil.tz import tzutc +from dateutil.tz import ( + tzlocal, + tzutc, +) import numpy as np import pytest import pytz @@ -23,6 +26,7 @@ maybe_get_tz, tz_compare, ) +from pandas.compat import IS64 from pandas.errors import OutOfBoundsDatetime import pandas.util._test_decorators as td @@ -150,8 +154,15 @@ def test_names(self, data, time_locale): assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale)) - def test_is_leap_year(self, tz_naive_fixture): + def test_is_leap_year(self, tz_naive_fixture, request): tz = tz_naive_fixture + if not IS64 and tz is tzlocal(): + request.node.add_marker(pytest.mark.filterwarnings("ignore::OverflowError")) + request.node.add_marker( + pytest.mark.filterwarnings( + "ignore::pytest.PytestUnraisableExceptionWarning" + ) + ) # GH 13727 dt = Timestamp("2000-01-01 00:00:00", tz=tz) assert dt.is_leap_year From b99158cb78d6f3eee18fa07f007877184a694896 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Sat, 18 Feb 2023 17:14:59 -0800 Subject: [PATCH 09/11] Try these changes --- pandas/tests/scalar/timestamp/test_timestamp.py | 2 +- pyproject.toml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 4cc45acc1b3a7..2783d75528c28 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -156,7 +156,7 @@ def test_names(self, data, time_locale): def test_is_leap_year(self, tz_naive_fixture, request): tz = tz_naive_fixture - if not IS64 and tz is tzlocal(): + if not IS64 and tz == tzlocal(): request.node.add_marker(pytest.mark.filterwarnings("ignore::OverflowError")) request.node.add_marker( pytest.mark.filterwarnings( diff --git a/pyproject.toml b/pyproject.toml index f56210b7d590c..9d4166b033128 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -396,10 +396,10 @@ doctest_optionflags = [ ] filterwarnings = [ "error::ResourceWarning", - "ignore:.*unclosed Date: Sat, 18 Feb 2023 18:17:24 -0800 Subject: [PATCH 10/11] Try the whole file? --- pandas/tests/scalar/timestamp/test_timestamp.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index 2783d75528c28..dfe4e5b4dc148 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -10,10 +10,7 @@ import time import unicodedata -from dateutil.tz import ( - tzlocal, - tzutc, -) +from dateutil.tz import tzutc import numpy as np import pytest import pytz @@ -26,7 +23,6 @@ maybe_get_tz, tz_compare, ) -from pandas.compat import IS64 from pandas.errors import OutOfBoundsDatetime import pandas.util._test_decorators as td @@ -154,15 +150,11 @@ def test_names(self, data, time_locale): assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale)) + # Caused by tzlocal() on 32 bit platforms + @pytest.mark.filterwarnings("ignore::OverflowError") + @pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") def test_is_leap_year(self, tz_naive_fixture, request): tz = tz_naive_fixture - if not IS64 and tz == tzlocal(): - request.node.add_marker(pytest.mark.filterwarnings("ignore::OverflowError")) - request.node.add_marker( - pytest.mark.filterwarnings( - "ignore::pytest.PytestUnraisableExceptionWarning" - ) - ) # GH 13727 dt = Timestamp("2000-01-01 00:00:00", tz=tz) assert dt.is_leap_year From 1daf6d7f04b5814fd66ef3fb45e977df530df34f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Sat, 18 Feb 2023 19:17:40 -0800 Subject: [PATCH 11/11] Just skip under condidition --- pandas/tests/scalar/timestamp/test_timestamp.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_timestamp.py b/pandas/tests/scalar/timestamp/test_timestamp.py index dfe4e5b4dc148..afb4dd7422114 100644 --- a/pandas/tests/scalar/timestamp/test_timestamp.py +++ b/pandas/tests/scalar/timestamp/test_timestamp.py @@ -10,7 +10,10 @@ import time import unicodedata -from dateutil.tz import tzutc +from dateutil.tz import ( + tzlocal, + tzutc, +) import numpy as np import pytest import pytz @@ -23,6 +26,7 @@ maybe_get_tz, tz_compare, ) +from pandas.compat import IS64 from pandas.errors import OutOfBoundsDatetime import pandas.util._test_decorators as td @@ -150,11 +154,13 @@ def test_names(self, data, time_locale): assert np.isnan(nan_ts.day_name(time_locale)) assert np.isnan(nan_ts.month_name(time_locale)) - # Caused by tzlocal() on 32 bit platforms - @pytest.mark.filterwarnings("ignore::OverflowError") - @pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") - def test_is_leap_year(self, tz_naive_fixture, request): + def test_is_leap_year(self, tz_naive_fixture): tz = tz_naive_fixture + if not IS64 and tz == tzlocal(): + # https://github.com/dateutil/dateutil/issues/197 + pytest.skip( + "tzlocal() on a 32 bit platform causes internal overflow errors" + ) # GH 13727 dt = Timestamp("2000-01-01 00:00:00", tz=tz) assert dt.is_leap_year