Skip to content

ResourceWarning: unclosed file in test_openml.py #19349

@cmarmo

Description

@cmarmo

Running the tests on opeml datasets throws a number of ResourceWarning in the last development version

Step to reproduce the issue

$ pytest -v sklearn/datasets/tests/test_openml.py -Werror

Expected result

The tests pass

Actual result

The tests fail with messages like

E               Traceback (most recent call last):
E                 File "/home/cmarmo/software/scikit-learn/sklearn/datasets/_openml.py", line 59, in wrapper
E                   return f(*args, **kw)
E               ResourceWarning: unclosed file <_io.BufferedReader name='/home/cmarmo/software/scikit-learn/sklearn/datasets/tests/data/openml/2/api-v1-json-data-qualities-2.json.gz'>

Additional comments

  • The exception seems to be always thrown from sklearn/datasets/_openml.py from the wrapper function:

    def wrapper(*args, **kw):
    if data_home is None:
    return f(*args, **kw)
    try:
    return f(*args, **kw)
    except HTTPError:
    raise
    except Exception:
    warn("Invalid cache, redownloading file", RuntimeWarning)
    local_path = _get_local_path(openml_path, data_home)
    if os.path.exists(local_path):
    os.unlink(local_path)
    return f(*args, **kw)
    return wrapper

  • Please open one PR for each test file with a failure reported with the command above instead of one single PR that tries to fix everything at once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ModerateAnything that requires some knowledge of conventions and best practicesSprintmodule:datasetsmodule:test-suiteeverything related to our tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions