Skip to content

Simple pickle and small metadata parse speedups#549

Merged
martindurant merged 6 commits intodask:masterfrom
martindurant:micro-impr
Jan 25, 2021
Merged

Simple pickle and small metadata parse speedups#549
martindurant merged 6 commits intodask:masterfrom
martindurant:micro-impr

Conversation

@martindurant
Copy link
Member

A bigger parse improvement, not yet made, would be to call val_to_num only if the type is known from the metadata (no guessing, which is error prone) or when filtering, to the type of user-supplied comparison value.
This is complicated by the partitioning column metadata being in terms of the original column names, but these get lost when reading drill-style paths (could get reapplied, of course).

@martindurant
Copy link
Member Author

@rjzamora , the pickle methods here should simplify your life a little.

@rjzamora
Copy link
Member

Thanks for working on this @martindurant !

Note that I am getting good performance with this PR, but I am getting some bad results for partitioned columns after I remove fmd.row_groups and do round-trip serialization. Note that the size of the graph is too large if I leave this row-group data in the fmd. I'll try to find the cause, but here is a reproducer:

from fastparquet import ParquetFile
import pickle
import dask.dataframe as dd
import pandas as pd
import numpy as np
import copy

base_path = "mytest"
metadata_path = "/".join([base_path, "_metadata"])
peice_path = './mytest/b=2001/c=2/part.0.parquet'

df = pd.DataFrame(
    {
        "a": np.random.rand(50),
        "b": np.random.choice([2001, 2002, 2003], size=50),
        "c": np.random.choice([1, 2, 3], size=50),
    }
)
df.index.name = "index"
dd.from_pandas(df, 2).to_parquet(base_path, partition_on=["b", "c"], engine="fastparquet")

# NO Pickle
pf = ParquetFile(metadata_path)
row_groups = [pf.row_groups[0]]
df = pf.read_row_group_file(pf.row_groups[0], ["a", "b", "c"], [])
print("\nGOOD - No Pickle\n", df)

# YES Pickle
pfc = pickle.loads(pickle.dumps(pf))
pfc.row_groups = row_groups
df = pfc.read_row_group_file(pfc.row_groups[0], ["a", "b", "c"], [])
print("\nGOOD - Yes Pickle\n", df)

# Strip `pf.fmd.row_groups` and Pickle
pf.fmd.row_groups = None  # THIS LINE CAUSES THE PROBLEM
pfc = pickle.loads(pickle.dumps(pf))
pfc.row_groups = row_groups
df = pfc.read_row_group_file(pfc.row_groups[0], ["a", "b", "c"], [])
print("\nBAD - Yes Pickle\n", df)
GOOD - No Pickle
               a     b  c
index                   
0      0.951766  2001  1
1      0.512150  2001  1

GOOD - Yes Pickle
               a     b  c
index                    
0      0.951766  2001  1
1      0.512150  2001  1

BAD - Yes Pickle
               a              b              c
index                                        
0      0.951766  4.647194e-310  9.050856e+223
1      0.512150   8.232378e+06  5.088876e-322

@martindurant
Copy link
Member Author

The following works:

# Strip `pf.fmd.row_groups` and Pickle
pf.fmd.row_groups = None  # THIS LINE CAUSES THE PROBLEM
pfc = pickle.loads(pickle.dumps(pf))
pfc.fmd.row_groups = row_groups
pfc._set_attrs()
df = pfc.read_row_group_file(pfc.row_groups[0], ["a", "b", "c"], [])

@martindurant martindurant merged commit d9cb86d into dask:master Jan 25, 2021
@martindurant martindurant deleted the micro-impr branch January 25, 2021 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants