3

I am currently trying to save and read information from dask to parquet files. But when trying to save a dataframe with dask "to_parquet" and loading it afterwards again with "read_parquet" it seems like the division information gets lost.

>>df.divisions
(Timestamp('2014-10-01 17:25:17.928000'), Timestamp('2014-10-01 17:27:18.000860'), Timestamp('2014-10-01 17:29:19.000860'), Timestamp('2014-10-01 17:31:19.000860'), Timestamp('2014-10-01 17:33:20.000860'), Timestamp('2014-10-01 17:35:20.763000'), Timestamp('2014-10-01 17:36:12.992860'))
>>df.to_parquet(folder)
>>del df
>>df = dask.dataframe.read_parquet(folder)
>>df.divisions
(None, None, None, None, None, None, None)

Is this intended? My current workaround is to set the index again after loading but that takes a lot of time.

>> df = dask.dataframe.read_parquet(folder,index=False).set_index('timestamp', sorted=True)
>> df.divisions
(Timestamp('2014-10-01 17:25:17.928000'), Timestamp('2014-10-01 17:27:18.000860'), Timestamp('2014-10-01 17:29:19.000860'), Timestamp('2014-10-01 17:31:19.000860'), Timestamp('2014-10-01 17:33:20.000860'), Timestamp('2014-10-01 17:35:20.763000'), Timestamp('2014-10-01 17:36:12.992860'))

Or am I missing some options while saving and loading?

lennart
  • 33
  • 3

1 Answers1

1

Tested with the fastparquet backend, appears to work:

> import pandas.util.testing as tm
> df = tm.makeTimeDataFrame()
> df
                   A         B         C         D
2000-01-03 -0.414197  0.459438  1.105962 -0.791487
2000-01-04 -0.875873  0.987601  0.881839 -1.339756
2000-01-05  0.552543  3.415769  1.008780  0.127757
...
> d = dd.from_pandas(df, 2)
> d.to_parquet('temp.parq')
> dd.read_parquet('temp.parq').divisions
(Timestamp('2000-01-03 00:00:00'),
 Timestamp('2000-01-24 00:00:00'),
 Timestamp('2000-02-11 00:00:00'))
mdurant
  • 27,272
  • 5
  • 45
  • 74
  • Thanks! You are right. After your answer I rechecked my data and recognized that the samples were not sorted correctly. After shuffling it with set_index(sorted=False) I am able to read/write the data with correct division information to parquet. – lennart Nov 24 '17 at 10:31