Skip to content

WIP/CI: Debug ResourceWarnings unclosed io.BufferedRandom #44634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
788725e
WIP/CI: Debug ResourceWarnings unclosed io.BufferedRandom
mroeschke Nov 27, 2021
3c0124a
Use if statement
mroeschke Nov 27, 2021
172af5a
Trigger CI
mroeschke Nov 27, 2021
cb17967
Add back azure for ResourceWarning checking
mroeschke Nov 27, 2021
0775d18
Also add psutil to azure deps
mroeschke Nov 27, 2021
66f58d3
Trigger CI
mroeschke Nov 27, 2021
81f37d5
Trigger CI
mroeschke Nov 27, 2021
696d217
Just import directly
mroeschke Nov 27, 2021
58c48cf
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 28, 2021
30e03b0
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 28, 2021
07aedcd
Trigger CI
mroeschke Nov 28, 2021
ce3348d
Trigger CI
mroeschke Nov 28, 2021
0652224
Trigger CI
mroeschke Nov 28, 2021
d4542a0
Trigger CI
mroeschke Nov 28, 2021
83ce5a7
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 28, 2021
ddd22da
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 29, 2021
3082ff4
Check warnings everywhere
mroeschke Nov 29, 2021
9455eb5
Only raise for ResourceWarning
mroeschke Nov 29, 2021
3dc24d4
-v in pytest, only print when there are files, install psutil in more…
mroeschke Nov 29, 2021
a8ff090
-v too verbose
mroeschke Nov 29, 2021
dcee412
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 29, 2021
2a506b3
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Nov 30, 2021
cff61e4
Merge remote-tracking branch 'upstream/master' into ci/debug/resource…
mroeschke Dec 1, 2021
8e8fa7d
Test that these ipython tests are the culprit
mroeschke Dec 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
python -m pip install --upgrade pip setuptools wheel
pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
pip install git+https://github.com/nedbat/coveragepy.git
pip install cython python-dateutil pytz hypothesis pytest>=6.2.5 pytest-xdist pytest-cov
pip install cython python-dateutil pytz hypothesis pytest>=6.2.5 pytest-xdist pytest-cov psutil
pip list

- name: Build Pandas
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-db-min.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# required
- numpy<1.20 # GH#39541 compat for pyarrow<3
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- pytest-cov>=2.10.1 # this is only needed in the coverage build, ref: GH 35737
- psutil

# pandas dependencies
- aiobotocore<2.0.0
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-locale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-xdist>=1.31
- pytest-asyncio>=0.12.0
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-locale_slow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- beautifulsoup4=4.8.2
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38-slow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-38.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- numpy
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-39-numpydev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- python-dateutil
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-39-slow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-cov
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/azure-macos-38.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- pytest-azurepipelines
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/azure-windows-38.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- pytest-azurepipelines
- psutil

# pandas dependencies
- blosc
Expand Down
1 change: 1 addition & 0 deletions ci/deps/azure-windows-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
- pytest-xdist>=1.31
- hypothesis>=5.5.3
- pytest-azurepipelines
- psutil

# pandas dependencies
- beautifulsoup4
Expand Down
1 change: 1 addition & 0 deletions ci/deps/circle-38-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ dependencies:
- flask
- pip:
- moto
- psutil
25 changes: 16 additions & 9 deletions pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,23 @@ def _assert_caught_no_extra_warnings(
# suppress these
continue

extra_warnings.append(
(
actual_warning.category.__name__,
actual_warning.message,
actual_warning.filename,
actual_warning.lineno,
)
)
warning_data = [
actual_warning.category.__name__,
actual_warning.message,
actual_warning.filename,
actual_warning.lineno,
]

if actual_warning.category == ResourceWarning:
import psutil

proc = psutil.Process()
flist = proc.open_files()
warning_data.append(flist)

extra_warnings.append(tuple(warning_data))

if extra_warnings:
if extra_warnings and any(data[0] == ResourceWarning for data in extra_warnings):
raise AssertionError(f"Caused unexpected warning(s): {repr(extra_warnings)}")


Expand Down
18 changes: 16 additions & 2 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
- Dtypes
- Misc
"""
# pyright: reportUntypedFunctionDecorator = false

from collections import abc
from datetime import (
date,
Expand All @@ -31,13 +29,17 @@
import operator
import os

# pyright: reportUntypedFunctionDecorator = false
import sys

from dateutil.tz import (
tzlocal,
tzutc,
)
import hypothesis
from hypothesis import strategies as st
import numpy as np
import psutil
import pytest
from pytz import (
FixedOffset,
Expand Down Expand Up @@ -199,6 +201,18 @@ def add_imports(doctest_namespace):
doctest_namespace["pd"] = pd


@pytest.fixture(autouse=True)
def check_bufferedrandom_resourcewarning():
proc = psutil.Process()
with tm.assert_produces_warning(None):
yield
# sys.stderr for xdist
# https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644
open_files = proc.open_files()
if open_files:
print(open_files, flush=True, file=sys.stderr)


# ----------------------------------------------------------------
# Common arguments
# ----------------------------------------------------------------
Expand Down
27 changes: 9 additions & 18 deletions pandas/tests/io/formats/test_printing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

import pandas._config.config as cf

Expand Down Expand Up @@ -120,16 +119,8 @@ def test_ambiguous_width(self):


class TestTableSchemaRepr:
@classmethod
def setup_class(cls):
pytest.importorskip("IPython")

from IPython.core.interactiveshell import InteractiveShell

cls.display_formatter = InteractiveShell.instance().display_formatter

def test_publishes(self):

def test_publishes(self, ip):
ipython = ip.instance(config=ip.config)
df = pd.DataFrame({"A": [1, 2]})
objects = [df["A"], df, df] # dataframe / series
expected_keys = [
Expand All @@ -140,13 +131,13 @@ def test_publishes(self):
opt = pd.option_context("display.html.table_schema", True)
for obj, expected in zip(objects, expected_keys):
with opt:
formatted = self.display_formatter.format(obj)
formatted = ipython.display_formatter.format(obj)
assert set(formatted[0].keys()) == expected

with_latex = pd.option_context("display.latex.repr", True)

with opt, with_latex:
formatted = self.display_formatter.format(obj)
formatted = ipython.display_formatter.format(obj)

expected = {
"text/plain",
Expand All @@ -156,7 +147,7 @@ def test_publishes(self):
}
assert set(formatted[0].keys()) == expected

def test_publishes_not_implemented(self):
def test_publishes_not_implemented(self, ip):
# column MultiIndex
# GH 15996
midx = pd.MultiIndex.from_product([["A", "B"], ["a", "b", "c"]])
Expand All @@ -165,7 +156,7 @@ def test_publishes_not_implemented(self):
opt = pd.option_context("display.html.table_schema", True)

with opt:
formatted = self.display_formatter.format(df)
formatted = ip.instance(config=ip.config).display_formatter.format(df)

expected = {"text/plain", "text/html"}
assert set(formatted[0].keys()) == expected
Expand All @@ -184,9 +175,9 @@ def test_config_default_off(self):

assert result is None

def test_enable_data_resource_formatter(self):
def test_enable_data_resource_formatter(self, ip):
# GH 10491
formatters = self.display_formatter.formatters
formatters = ip.instance(config=ip.config).display_formatter.formatters
mimetype = "application/vnd.dataresource+json"

with pd.option_context("display.html.table_schema", True):
Expand All @@ -202,4 +193,4 @@ def test_enable_data_resource_formatter(self):
assert "application/vnd.dataresource+json" in formatters
assert formatters[mimetype].enabled
# smoke test that it works
self.display_formatter.format(cf)
ip.instance(config=ip.config).display_formatter.format(cf)