Skip to content

Appending to parquet file seems to break future appending #3098

Closed

Description

@shughes-uk

Dask 0.16.1, Fastparquet 0.1.3

This seems to be a dask problem as replicating the issue in fastparquet doesn't cause any kind of exception.

Appending to a hive parquet folder seems to break something and future appends fail. Not sure what's special about this use case (perhaps the datetimeindex?). Replication code and the exception are blow.

from datetime import datetime

import dask.dataframe as dd
import fastparquet
import numpy as np
import pandas as pd


d_range = pd.date_range(start='2017-01-01', end='2017-01-02', freq='1h')
df = pd.DataFrame(np.random.randn(len(d_range), 1), index=d_range, columns=list('A'))
ddf = dd.from_pandas(df, npartitions=1)
fastparquet.write('test_parq_fp', df, file_scheme='hive')
ddf.to_parquet('test_parq_dask')

d_range = pd.date_range(start='2017-01-02', end='2017-01-03', freq='1h')
df = pd.DataFrame(np.random.randn(len(d_range), 1), index=d_range, columns=list('A'))
ddf = dd.from_pandas(df, npartitions=1)
fastparquet.write('test_parq_fp', df, append=True, file_scheme='hive')
ddf.to_parquet('test_parq_dask', append=True)

d_range = pd.date_range(start='2017-01-04', end='2017-01-05', freq='1h')
df = pd.DataFrame(np.random.randn(len(d_range), 1), index=d_range, columns=list('A'))
ddf = dd.from_pandas(df, npartitions=1)
fastparquet.write('test_parq_fp', df, append=True, file_scheme='hive')
ddf.to_parquet('test_parq_dask', append=True)
Traceback (most recent call last):
  File "break_parquet.py", line 26, in <module>
    ddf.to_parquet('test_parq_dask', append=True)
  File "/Users/shughes/miniconda3/lib/python3.6/site-packages/dask/dataframe/core.py", line 1010, in to_parquet
    return to_parquet(self, path, *args, **kwargs)
  File "/Users/shughes/miniconda3/lib/python3.6/site-packages/dask/dataframe/io/parquet.py", line 840, in to_parquet
    storage_options=storage_options, **kwargs)
  File "/Users/shughes/miniconda3/lib/python3.6/site-packages/dask/dataframe/io/parquet.py", line 420, in _write_fastparquet
    old_end = minmax[index_cols[0]]['max'][-1]
KeyError: 'index'

Activity

  1. martindurant commented on Jan 24, 2018

    @martindurant
    Member

    Can you try with #3097 ?

  2. martindurant commented on Jan 24, 2018

    @martindurant
    Member

    The following change in fastparquet.api seems to fix this.

    L673                        all(mx <= mn for mx, mn in zip(max[:-1], min[1:]))):
    

    (condition goes to "less than or equal")

    I'd appreciate someone else's thoughts on whether this is the right fix.

  3. martindurant commented on Jan 24, 2018

    @martindurant
    Member
    In [8]: pd.date_range(start='2017-01-01', end='2017-01-02', freq='1h').max()
    Out[8]: Timestamp('2017-01-02 00:00:00', freq='H')
    
    In [9]: pd.date_range(start='2017-01-02', end='2017-01-03', freq='1h').min()
    Out[9]: Timestamp('2017-01-02 00:00:00', freq='H')
    

    ... because times repeat, last entry in one partition versus first in next.

    Note, you can always use ignore_divisions=True.

  4. shughes-uk commented on Jan 24, 2018

    @shughes-uk
    ContributorAuthor

    Tried #3097 with no joy . I guess my problem is that instead of throwing the usual 'Divisions overlap' exception it throws something much harder to understand.

  5. martindurant commented on Jan 24, 2018

    @martindurant
    Member

    Right, the case is not that the new data's divisions overlap with existing data, but that the original data doesn't have non-overlapping divisions in the first case. Except that they don't quite overlap, which is why I'm on the fence about whether this is a bug or not.

  6. mrocklin commented on Oct 24, 2018

    @mrocklin
    Member

    @martindurant is there something to fix here? If so can you summarize it? If not can you close?

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions