Repository navigation
Support categories= argument for pyarrow - #3177
Conversation
30242cb to
7bdb3d3
Compare
|
Any way this can be made to be backwards compatible with older versions of pyarrow? I'm fine with either:
The first one is probably easier, not sure. Up to you. |
|
@jcrist I went the long way and implemented three paths. Each one being the fastest for the given PyArrow version. While the one for 0.8 is quite lengthy, it should be much faster (mostly due to less memory copies) than the one that falls back to Pandas. |
| table = table.add_column(i, new_col) | ||
| df = table.to_pandas() | ||
| for cat in remaining_cats: | ||
| df[cat] = df[cat].astype('category') |
There was a problem hiding this comment.
Is there a strong benefit to doing it this way? I'm half tempted to just fall back to the simple pandas method due to maintenance costs. I suspect people using pyarrow are fairly quick to upgrade to new releases.
There was a problem hiding this comment.
Given that we will hopefully release pyarrow in the next two weeks, I'm going to remove this again
| dtypes = _get_pyarrow_dtypes(schema, categories) | ||
| dtypes = {storage_name_mapping.get(k, k): v for k, v in dtypes.items()} | ||
|
|
||
| meta = _meta_from_dtypes(all_columns, dtypes, index_names, column_index_names) |
There was a problem hiding this comment.
Since we don't know the actual categories at graph build time, we need to make sure any categorical columns/indices are marked as unknown categories (see http://dask.pydata.org/en/latest/dataframe-design.html#categoricals). The fastparquet reader handles this here: https://github.com/dask/dask/pull/3177/files#diff-410a8a0995091d42fbbbc5a50efda3aeL295, but this looks incorrect for the no-data case, as meta is returned directly on compute and would then have the string '__UNKNOWN_CATEGORIES__' in its categories.
Ideally we'd have two objects:
- An empty frame/series that can be returned directly to the user on compute in the case of no data
- An empty frame/series to be used as metadata that properly sets unknown categories
These should ideally be handled using the same code path (perhaps move logic to _meta_from_dtypes). You might also find dask.dataframe.utils.clear_known_categories (sets all categories to be unknown) and dask.dataframe.utils.strip_unknown_categories (removes unknown categories flags) to be useful.
There was a problem hiding this comment.
Adjusted it hopefully in the correct way. Moving the code to _meta_from_dtype depends on the pyarrow path also supporting known categoricals. I'm not sure how soon I'll get to that.
d3fd17d to
b56a021
Compare
|
Travis failure is due to a job exceeding the maximal execution time. |
|
Restarted. Tests pass |
|
Thanks @xhochy! |
flake8 daskdocs/source/changelog.rstfor all changesand one of the
docs/source/*-api.rstfiles for new APIDepends on apache/arrow#1620 (should be part of the upcoming 0.9 release)
fastparquet->pyarrowroundtrip fails due to dask/fastparquet#305