brightway-lca / bw_processing

Tools to create structured arrays in a common format
https://docs.brightway.dev/projects/bw-processing/
BSD 3-Clause "New" or "Revised" License
7 stars 5 forks source link

python 3.8 tests fail #59

Closed tngTUDOR closed 5 months ago

tngTUDOR commented 5 months ago

Current

Tests with python 3.8 fail with errors similar to

__________ test_save_load_parquet_file[indices_vector-vector-indices] __________

arr_fixture_name = 'indices_vector', meta_object = 'vector'
meta_type = 'indices'
tmp_path_factory = TempPathFactory(_given_basetemp=None, _trace=<pluggy._tracing.TagTracerSub object at 0x7f420e731070>, _basetemp=PosixPath('/tmp/pytest-of-runner/pytest-0'), _retention_count=3, _retention_policy='all')
request = <FixtureRequest for <Function test_save_load_parquet_file[indices_vector-vector-indices]>>
    @pytest.mark.parametrize("arr_fixture_name, meta_object, meta_type", ARR_LIST)
    def test_save_load_parquet_file(
        arr_fixture_name, meta_object, meta_type, tmp_path_factory, request
    ):

        arr = request.getfixturevalue(arr_fixture_name)  # get fixture from name
        file = tmp_path_factory.mktemp("data") / (arr_fixture_name + ".parquet")
        with file as fp:
            save_arr_to_parquet(
                file=fp, arr=arr, meta_object=meta_object, meta_type=meta_type
            )
>       with file as fp:
tests/io_parquet_helpers.py:39: 

The interesting part to "debug" / fix: E ValueError: I/O operation on closed path

tests/io_parquet_helpers.py:39: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/pathlib.py:1067: in __enter__
    self._raise_closed()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = PosixPath('/tmp/pytest-of-runner/pytest-0/data0/indices_vector.parquet')

    def _raise_closed(self):
>       raise ValueError("I/O operation on closed path")
E       ValueError: I/O operation on closed path

Expected

cmutel commented 5 months ago

I think we are 3.8 compatible, but maybe not the parquet stuff. Hard to tell if this is a CI filesystem bug or not. But in any case, the people running 3.8 don't need the latest and greatest, like Parquet support, so it's fine for now.

tngTUDOR commented 5 months ago

For some reason, the second time we use a fp, in py 3.8, it has already been closed, per the "context" way of using it (with file as fp:). Another wayto fix this is to use a "Path" after the first use of the file/fp.

This seems to me really like it's only a python 3.8 problem, since tests seem to pass for other versions.