Skip to content

Flaky test_create_metadata_file #8062

Closed

Description

@jrbourbeau

Over in #8057 we observed dask/dataframe/io/tests/test_parquet.py::test_create_metadata_file[pyarrow-dataset-fastparquet-a] failed due to a DataFrame shape mismatch in one CI build (full traceback below). This seems unrelated to the changes in that PR as the test itself doesn't specify overwrite=True.

Full traceback:
2021-08-17T22:44:03.7164386Z ___________ test_create_metadata_file[pyarrow-dataset-fastparquet-a] ___________
2021-08-17T22:44:03.7165991Z [gw0] linux -- Python 3.8.10 /usr/share/miniconda3/envs/test-environment/bin/python
2021-08-17T22:44:03.7166803Z 
2021-08-17T22:44:03.7167967Z tmpdir = '/tmp/pytest-of-runner/pytest-0/popen-gw0/test_create_metadata_file_pyar1'
2021-08-17T22:44:03.7169778Z write_engine = 'pyarrow-dataset', read_engine = 'fastparquet'
2021-08-17T22:44:03.7170803Z partition_on = 'a'
2021-08-17T22:44:03.7171314Z 
2021-08-17T22:44:03.7171896Z     @PYARROW_MARK
2021-08-17T22:44:03.7172920Z     @pytest.mark.parametrize("partition_on", [None, "a"])
2021-08-17T22:44:03.7173827Z     @write_read_engines()
2021-08-17T22:44:03.7174757Z     def test_create_metadata_file(tmpdir, write_engine, read_engine, partition_on):
2021-08-17T22:44:03.7175711Z         tmpdir = str(tmpdir)
2021-08-17T22:44:03.7176313Z     
2021-08-17T22:44:03.7176967Z         # Write ddf without a _metadata file
2021-08-17T22:44:03.7177813Z         df1 = pd.DataFrame({"b": range(100), "a": ["A", "B", "C", "D"] * 25})
2021-08-17T22:44:03.7178620Z         df1.index.name = "myindex"
2021-08-17T22:44:03.7179443Z         ddf1 = dd.from_pandas(df1, npartitions=10)
2021-08-17T22:44:03.7180198Z         ddf1.to_parquet(
2021-08-17T22:44:03.7180827Z             tmpdir,
2021-08-17T22:44:03.7181511Z             write_metadata_file=False,
2021-08-17T22:44:03.7182257Z             partition_on=partition_on,
2021-08-17T22:44:03.7183002Z             engine=write_engine,
2021-08-17T22:44:03.7184369Z         )
2021-08-17T22:44:03.7184874Z     
2021-08-17T22:44:03.7185446Z         # Add global _metadata file
2021-08-17T22:44:03.7186085Z         if partition_on:
2021-08-17T22:44:03.7186882Z             fns = glob.glob(os.path.join(tmpdir, partition_on + "=*/*.parquet"))
2021-08-17T22:44:03.7187644Z         else:
2021-08-17T22:44:03.7188338Z             fns = glob.glob(os.path.join(tmpdir, "*.parquet"))
2021-08-17T22:44:03.7189208Z         dd.io.parquet.create_metadata_file(
2021-08-17T22:44:03.7189896Z             fns,
2021-08-17T22:44:03.7190434Z             engine="pyarrow",
2021-08-17T22:44:03.7191122Z             split_every=3,  # Force tree reduction
2021-08-17T22:44:03.7191863Z         )
2021-08-17T22:44:03.7192855Z     
2021-08-17T22:44:03.7193451Z         # Check that we can now read the ddf
2021-08-17T22:44:03.7194163Z         # with the _metadata file present
2021-08-17T22:44:03.7194842Z         ddf2 = dd.read_parquet(
2021-08-17T22:44:03.7195412Z             tmpdir,
2021-08-17T22:44:03.7196016Z             gather_statistics=True,
2021-08-17T22:44:03.7196676Z             split_row_groups=False,
2021-08-17T22:44:03.7197303Z             engine=read_engine,
2021-08-17T22:44:03.7198349Z             index="myindex",  # python-3.6 CI
2021-08-17T22:44:03.7198945Z         )
2021-08-17T22:44:03.7199476Z         if partition_on:
2021-08-17T22:44:03.7200082Z             ddf1 = df1.sort_values("b")
2021-08-17T22:44:03.7200788Z             ddf2 = ddf2.compute().sort_values("b")
2021-08-17T22:44:03.7201541Z             ddf2.a = ddf2.a.astype("object")
2021-08-17T22:44:03.7202192Z >       assert_eq(ddf1, ddf2)
2021-08-17T22:44:03.7202625Z 
2021-08-17T22:44:03.7203333Z dask/dataframe/io/tests/test_parquet.py:3384: 
2021-08-17T22:44:03.7204024Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2021-08-17T22:44:03.7204451Z 
2021-08-17T22:44:03.7204917Z a =           b  a
2021-08-17T22:44:03.7205426Z myindex       
2021-08-17T22:44:03.7205927Z 0         0  A
2021-08-17T22:44:03.7206385Z 1         1  B
2021-08-17T22:44:03.7206854Z 2         2  C
2021-08-17T22:44:03.7207330Z 3         3  D
2021-08-17T22:44:03.7207809Z 4         4  A
2021-08-17T22:44:03.7208280Z ...      .. ..
2021-08-17T22:44:03.7208752Z 95       95  D
2021-08-17T22:44:03.7209211Z 96       96  A
2021-08-17T22:44:03.7209661Z 97       97  B
2021-08-17T22:44:03.7210128Z 98       98  C
2021-08-17T22:44:03.7210594Z 99       99  D
2021-08-17T22:44:03.7210940Z 
2021-08-17T22:44:03.7211451Z [100 rows x 2 columns]
2021-08-17T22:44:03.7211976Z b =           b  a
2021-08-17T22:44:03.7212598Z myindex       
2021-08-17T22:44:03.7213100Z 0         0  A
2021-08-17T22:44:03.7213555Z 1         1  B
2021-08-17T22:44:03.7214047Z 2         2  C
2021-08-17T22:44:03.7214818Z 3         3  D
2021-08-17T22:44:03.7215395Z 4         4  A
2021-08-17T22:44:03.7217661Z ...      .. ..
2021-08-17T22:44:03.7218102Z 95       95  D
2021-08-17T22:44:03.7218450Z 96       96  A
2021-08-17T22:44:03.7218784Z 97       97  B
2021-08-17T22:44:03.7219130Z 98       98  C
2021-08-17T22:44:03.7219462Z 99       99  D
2021-08-17T22:44:03.7219711Z 
2021-08-17T22:44:03.7220092Z [99 rows x 2 columns]
2021-08-17T22:44:03.7220702Z check_names = True, check_dtype = True, check_divisions = True
2021-08-17T22:44:03.7221356Z check_index = True, kwargs = {}
2021-08-17T22:44:03.7221690Z 
2021-08-17T22:44:03.7222054Z     def assert_eq(
2021-08-17T22:44:03.7222443Z         a,
2021-08-17T22:44:03.7222775Z         b,
2021-08-17T22:44:03.7223184Z         check_names=True,
2021-08-17T22:44:03.7223640Z         check_dtype=True,
2021-08-17T22:44:03.7224130Z         check_divisions=True,
2021-08-17T22:44:03.7224607Z         check_index=True,
2021-08-17T22:44:03.7225046Z         **kwargs,
2021-08-17T22:44:03.7225397Z     ):
2021-08-17T22:44:03.7225806Z         if check_divisions:
2021-08-17T22:44:03.7226297Z             assert_divisions(a)
2021-08-17T22:44:03.7226802Z             assert_divisions(b)
2021-08-17T22:44:03.7227429Z             if hasattr(a, "divisions") and hasattr(b, "divisions"):
2021-08-17T22:44:03.7228204Z                 at = type(np.asarray(a.divisions).tolist()[0])  # numpy to python
2021-08-17T22:44:03.7229033Z                 bt = type(np.asarray(b.divisions).tolist()[0])  # scalar conversion
2021-08-17T22:44:03.7229687Z                 assert at == bt, (at, bt)
2021-08-17T22:44:03.7230195Z         assert_sane_keynames(a)
2021-08-17T22:44:03.7230708Z         assert_sane_keynames(b)
2021-08-17T22:44:03.7231399Z         a = _check_dask(a, check_names=check_names, check_dtypes=check_dtype)
2021-08-17T22:44:03.7232224Z         b = _check_dask(b, check_names=check_names, check_dtypes=check_dtype)
2021-08-17T22:44:03.7232990Z         if not check_index:
2021-08-17T22:44:03.7233505Z             a = a.reset_index(drop=True)
2021-08-17T22:44:03.7234030Z             b = b.reset_index(drop=True)
2021-08-17T22:44:03.7234564Z         if hasattr(a, "to_pandas"):
2021-08-17T22:44:03.7235727Z             a = a.to_pandas()
2021-08-17T22:44:03.7236212Z         if hasattr(b, "to_pandas"):
2021-08-17T22:44:03.7236676Z             b = b.to_pandas()
2021-08-17T22:44:03.7237215Z         if isinstance(a, pd.DataFrame):
2021-08-17T22:44:03.7237735Z             a = _maybe_sort(a)
2021-08-17T22:44:03.7238176Z             b = _maybe_sort(b)
2021-08-17T22:44:03.7238804Z >           tm.assert_frame_equal(a, b, check_dtype=check_dtype, **kwargs)
2021-08-17T22:44:03.7239592Z E           AssertionError: DataFrame are different
2021-08-17T22:44:03.7240143Z E           
2021-08-17T22:44:03.7240587Z E           DataFrame shape mismatch
2021-08-17T22:44:03.7241076Z E           [left]:  (100, 2)
2021-08-17T22:44:03.7241476Z E           [right]: (99, 2)
2021-08-17T22:44:03.7241758Z 
2021-08-17T22:44:03.7242279Z dask/dataframe/utils.py:555: AssertionError

Activity

  1. added
    tests
    on Aug 18, 2021
  2. added
    needs attention
    on Oct 25, 2021
  3. jcrist commented on Mar 1, 2022

    @jcrist
    Member

    Looking through our test failure history, this no longer appears to be a flaky test. Closing.

  4. reopened this on Apr 7, 2022
  5. jcrist commented on Apr 7, 2022

    @jcrist
    Member

    I've started seeing this test failure again, this time with fastparquet alone (cc @martindurant). Example failure: https://github.com/dask/dask/runs/5872450945?check_suite_focus=true#step:6:21161.

    Traceback
    _____________ test_create_metadata_file[fastparquet-fastparquet-a] _____________
    [gw1] linux -- Python 3.9.12 /usr/share/miniconda3/envs/test-environment/bin/python
    
    tmpdir = '/tmp/pytest-of-runner/pytest-0/popen-gw1/test_create_metadata_file_fast1'
    write_engine = 'fastparquet', read_engine = 'fastparquet', partition_on = 'a'
    
        @PYARROW_MARK
        @pytest.mark.parametrize("partition_on", [None, "a"])
        @write_read_engines()
        def test_create_metadata_file(tmpdir, write_engine, read_engine, partition_on):
            tmpdir = str(tmpdir)
        
            # Write ddf without a _metadata file
            df1 = pd.DataFrame({"b": range(100), "a": ["A", "B", "C", "D"] * 25})
            df1.index.name = "myindex"
            ddf1 = dd.from_pandas(df1, npartitions=10)
            ddf1.to_parquet(
                tmpdir,
                write_metadata_file=False,
                partition_on=partition_on,
                engine=write_engine,
            )
        
            # Add global _metadata file
            if partition_on:
                fns = glob.glob(os.path.join(tmpdir, partition_on + "=*/*.parquet"))
            else:
                fns = glob.glob(os.path.join(tmpdir, "*.parquet"))
            dd.io.parquet.create_metadata_file(
                fns,
                engine="pyarrow",
                split_every=3,  # Force tree reduction
            )
        
            # Check that we can now read the ddf
            # with the _metadata file present
            ddf2 = dd.read_parquet(
                tmpdir,
                gather_statistics=True,
                split_row_groups=False,
                engine=read_engine,
                index="myindex",  # python-3.6 CI
            )
            if partition_on:
                ddf1 = df1.sort_values("b")
                ddf2 = ddf2.compute().sort_values("b")
                ddf2.a = ddf2.a.astype("object")
    >       assert_eq(ddf1, ddf2)
    
    dask/dataframe/io/tests/test_parquet.py:3369: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    dask/dataframe/utils.py:555: in assert_eq
        tm.assert_frame_equal(
    pandas/_libs/testing.pyx:53: in pandas._libs.testing.assert_almost_equal
        ???
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    >   ???
    E   AssertionError: DataFrame.index are different
    E   
    E   DataFrame.index values are different (28.0 %)
    E   [left]:  Int64Index([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
    E               17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
    E               34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
    E               51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
    E               68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
    E               85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
    E              dtype='int64', name='myindex')
    E   [right]: Int64Index([ 0,  2,  3,  4,  6,  7,  8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
    E               20, 21, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33,
    E               34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
    E               51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
    E               68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
    E               85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
    E              dtype='int64', name='myindex')
    
    pandas/_libs/testing.pyx:168: AssertionError
  6. martindurant commented on Apr 7, 2022

    @martindurant
    Member

    Hm, I run it many times locally and it always passes, which makes it annoying! Would it be something like the metadata file hasn't made it to the disk yet?

  7. jcrist commented on Apr 7, 2022

    @jcrist
    Member

    🤷 If you look at the traceback above, it looks like the indices differ (different missing values in each). Is the index here meaningful? Should check_index=False be passed here?

  8. martindurant commented on Apr 7, 2022

    @martindurant
    Member

    I think it may be that pyarrow is taking the index from global metadata and fastparquet is taking it from the individual files, allowing for some randomisaton. I am not sure. We are reordering the data on load with non-unique values, so we could check that the columns we care about have the same value_counts, but I feel like the index ought to match too.

  9. self-assigned this
    on Aug 4, 2022
  10. j-bennet commented on Mar 17, 2023

    @j-bennet
    Contributor

    This still happens, but the problem does not look exactly the same. It only happens when writing with pyarrow and reading with fastparquet. And it looks like we're sometimes reading back 101 records, even though we're writing 100 records. And what's up with those duplicated index records:

    b =           b  a
    myindex       
    0         0  A
    1         1  B
    2         2  C
    3         3  D
    4         4  A
    ...      .. ..
    96       96  A
    97       97  B
    98       98  C
    99       99  D
    99       99  D
    
    [101 rows x 2 columns]

    Full traceback:

    _______________ test_create_metadata_file[pyarrow-fastparquet-a] _______________
    [gw3] darwin -- Python 3.11.0 /Users/runner/miniconda3/envs/test-environment/bin/python3.11
    
    tmpdir = '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pytest-of-runner/pytest-0/popen-gw3/test_create_metadata_file_pyar1'
    write_engine = 'pyarrow', read_engine = 'fastparquet', partition_on = 'a'
    
        @PYARROW_MARK
        @pytest.mark.parametrize("partition_on", [None, "a"])
        @write_read_engines()
        def test_create_metadata_file(tmpdir, write_engine, read_engine, partition_on):
            tmpdir = str(tmpdir)
        
            # Write ddf without a _metadata file
            df1 = pd.DataFrame({"b": range(100), "a": ["A", "B", "C", "D"] * 25})
            df1.index.name = "myindex"
            ddf1 = dd.from_pandas(df1, npartitions=10)
            ddf1.to_parquet(
                tmpdir,
                write_metadata_file=False,
                partition_on=partition_on,
                engine=write_engine,
            )
        
            # Add global _metadata file
            if partition_on:
                fns = glob.glob(os.path.join(tmpdir, partition_on + "=*/*.parquet"))
            else:
                fns = glob.glob(os.path.join(tmpdir, "*.parquet"))
            dd.io.parquet.create_metadata_file(
                fns,
                engine="pyarrow",
                split_every=3,  # Force tree reduction
            )
        
            # Check that we can now read the ddf
            # with the _metadata file present
            ddf2 = dd.read_parquet(
                tmpdir,
                calculate_divisions=True,
                split_row_groups=False,
                engine=read_engine,
                index="myindex",  # python-3.6 CI
            )
            if partition_on:
                ddf1 = df1.sort_values("b")
                ddf2 = ddf2.compute().sort_values("b")
                ddf2.a = ddf2.a.astype("object")
    >       assert_eq(ddf1, ddf2)
    
    dask/dataframe/io/tests/test_parquet.py:3876: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    
    a =           b  a
    myindex       
    0         0  A
    1         1  B
    2         2  C
    3         3  D
    4         4  A
    ...      .. ..
    95       95  D
    96       96  A
    97       97  B
    98       98  C
    99       99  D
    
    [100 rows x 2 columns]
    b =           b  a
    myindex       
    0         0  A
    1         1  B
    2         2  C
    3         3  D
    4         4  A
    ...      .. ..
    96       96  A
    97       97  B
    98       98  C
    99       99  D
    99       99  D
    
    [101 rows x 2 columns]
    check_names = True, check_dtype = True, check_divisions = True
    check_index = True, sort_results = True, scheduler = 'sync', kwargs = {}
    
        def assert_eq(
            a,
            b,
            check_names=True,
            check_dtype=True,
            check_divisions=True,
            check_index=True,
            sort_results=True,
            scheduler="sync",
            **kwargs,
        ):
            if check_divisions:
                assert_divisions(a, scheduler=scheduler)
                assert_divisions(b, scheduler=scheduler)
                if hasattr(a, "divisions") and hasattr(b, "divisions"):
                    at = type(np.asarray(a.divisions).tolist()[0])  # numpy to python
                    bt = type(np.asarray(b.divisions).tolist()[0])  # scalar conversion
                    assert at == bt, (at, bt)
            assert_sane_keynames(a)
            assert_sane_keynames(b)
            a = _check_dask(
                a, check_names=check_names, check_dtypes=check_dtype, scheduler=scheduler
            )
            b = _check_dask(
                b, check_names=check_names, check_dtypes=check_dtype, scheduler=scheduler
            )
            if hasattr(a, "to_pandas"):
                a = a.to_pandas()
            if hasattr(b, "to_pandas"):
                b = b.to_pandas()
        
            a, b = _maybe_convert_string(a, b)
        
            if isinstance(a, (pd.DataFrame, pd.Series)) and sort_results:
                a = _maybe_sort(a, check_index)
                b = _maybe_sort(b, check_index)
            if not check_index:
                a = a.reset_index(drop=True)
                b = b.reset_index(drop=True)
            if isinstance(a, pd.DataFrame):
    >           tm.assert_frame_equal(
                    a, b, check_names=check_names, check_dtype=check_dtype, **kwargs
    E               AssertionError: DataFrame are different
    E               
    E               DataFrame shape mismatch
    E               [left]:  (100, 2)
    E               [right]: (101, 2)
    
    dask/dataframe/utils.py:594: AssertionError
  11. martindurant commented on Mar 21, 2023

    @martindurant
    Member

    Running pytest -k test_create_metadata_file --count 30 results in

    240 passed
    

    :|

  12. mrocklin commented on Jan 16, 2024

    @mrocklin
    Member

    I just ran into this in https://github.com/dask/dask/actions/runs/7482068503/job/20364896119?pr=10778. It doesn't look like there's anyone with motivation to fix this functionality. I propose that we xfail this test.

  13. phofl commented on Jan 17, 2024

    @phofl
    Collaborator

    I'll configure it to run with arrow only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

dataframeioneeds attentionparquettests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions