Writing and reading known categorical to parquet results in forgetting categories
See original GitHub issueTo reproduce:
- create dask dataframe with categorical column with known categories
- save it to parquet
- read it from parquet
- categories are unknown.
import dask.dataframe as dd
import pandas as pd
df = pd.DataFrame(data=list('abcaabbcc'), columns=['col'])
df.col = df.col.astype('category')
ddf = dd.from_pandas(df, npartitions=1)
ddf.to_parquet('tmp')
ddf2 = dd.read_parquet('tmp')
>>> ddf.col
Dask Series Structure:
npartitions=1
0 category[known]
8 ...
Name: col, dtype: category
Dask Name: getitem, 2 tasks
>>> ddf2.col
Dask Series Structure:
npartitions=1
0 category[unknown]
8 ...
Name: col, dtype: category
Dask Name: getitem, 2 tasks
dask: 0.16.0 fastparquet: 0.1.3 pandas: 0.21.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
Pandas DataFrame with categorical columns from a Parquet ...
But when I read the data into Pandas for further analysis using from_parquet I can not seem to recover the category dtypes. The...
Read more >Categoricals - Dask documentation
Dask DataFrame divides categorical data into two types: Known categoricals have the ... If you write and read to parquet, Dask will forget...
Read more >Reading and Writing the Apache Parquet Format
Categorical when converted to pandas. This option is only valid for string and binary column types, and it can yield significantly lower memory...
Read more >*Deep Dive – Parquet for Spark – Azure Data Ninjago & dqops
In this blog post, I am going to dive into the vectorised Parquet file reading in Spark. Vectorised Parquet file reader is a...
Read more >Best Practices for Amazon Redshift Spectrum | AWS Big Data ...
As of this writing, Amazon Redshift Spectrum supports Gzip, ... and maximum indexes and skips reading entire row groups for parquet files ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Shouldn’t this be mentioned in documentation about categoricals? I had this issue come up while working with categoricals, and it took me some time to figure out how to fix it.
https://github.com/dask/dask/issues/2947 for that last issue with
astype
.I think something like
will work in the meantime.