Repository navigation
DataFrame metadata cleanup - #1422
Conversation
- Forbid untyped dataframes, removing optional `dtype` compute. This causes lots of errors that need to be squashed - Start adding metadata inference in places where it's missing.
- Rename `nonempty_sample_df` to `nonempty_pd`. Make work with `pd.Series`, `pd.DataFrame` and `pd.Index` objects. Ensure that names, dtype, index type, and index name are all appropriately copied. - Move `_pd_nonempty` property to `_Frame` base class - Improve metadata inference for reductions.
No longer needed?
|
Follow + volunteer to contribute. Right now I am manually creating dask dataframes and enjoy dask's ability to keep going without full knowledge prior to computation. Actually, to be honest - this scares me a little. I'll manage though, and i'm probably not the common case here. |
| return df.map_partitions(func, columns=df.columns) | ||
|
|
||
| meta = func(df._pd) | ||
| return df.map_partitions(func, columns=meta) |
There was a problem hiding this comment.
Request that we eventually change columns= to meta= or some other word like empty, sample, dummy, etc..
Try the function on |
Hooray |
|
This is proving more difficult than expected. The main source of frustration is the implicit conversion of integers to floats if an operation finds missing data. For example, joining two indexed dataframes together with integer columns may result in integer columns or float columns, depending on if any missing rows are found in the join. This is impossible to infer beforehand, and is also impossible to infer by just evaluating the first few rows of a partition (as is currently done) because it depends on a global presence of missingness in the column. I'm not sure what to do here. Perhaps just do our best, but don't necessarily error in tests if numeric dtypes differ for operations where missingness can appear? |
|
That sounds reasonable to me. The only checks that really seem to care about this seem to be checks for number-y-ness. Alternatively we could coerce everything to float if it came to that? |
- `eq` now checks that the inferred dtypes match the computed dtypes. Note that all numeric types are compared equally, as pandas will implicitly convert integers to floats in the presence of missing data, which makes inference *hard*. There's not an obvious good way around this, so this will do for now. - `nonempty_pd` now returns 2 rows. Due to some bugs in pandas, there are differences in behavior between 1 row and 2 rows for some operations.
Notably `from_dask_array` inference with struct dtype now matches. Cleaned up a few implementation details of that inference function.
The implementation of `from_castra` lives in the castra repo, and doesn't propogate the dtype information, resulting in test failures. Xfailing these for now.
If not provided, metadata inference is first tried on fake data. If that fails, it's then tried on `head()`. If that fails, then we error, and suggest the user provide `meta`.
Add in `meta` keyword to dask.dataframe use functions (`map_partitions`, `apply`, `map`, etc...). A few other small things to squash throughout, and everything *should* pass fine now.
No longer needed, covered by the `make_meta` function.
More consistent naming of arguments/variables.
More robust to older versions of pandas.
|
This is ready for review. A few notes:
|
|
In the dict case how do we determine the order of the columns? |
|
That's a good point, I suppose we don't. This hasn't come up yet, as all cases where I've used the |
|
|
||
| msg = r"from_array does not input more than 2D array, got array with shape \(3, 3, 3\)" | ||
| with tm.assertRaisesRegexp(ValueError, msg): | ||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
I had to change how that function was implemented, and pulled the error checking into our code (which changed what they read). I didn't see the value in checking that the messages matched, but could change back if desired.
|
At a first glance through this all looks pretty reasonable to me. I haven't checked things like coverage though. |
More consistent naming througout.
- Remove inference from `df.head()`, as it can be slow and unexpected. Seems more sane to error in these cases and inform the user. - Change error message in `make_meta`. - A few small doc/pep8 fixes.
|
Ok, I think this is good to go now (minus a good review). I expect there might be some unexpected fallout from this, so it'd be good to get it in master soon so others can start playing with it and finding the edge cases that I couldn't. A few breaking changes I'd like to point out:
Everything else should be a smooth transition. Functions like |
| Arguments and keywords to pass to the function. The partition will | ||
| be the first argument, and these will be passed *after*. | ||
| meta : pd.DataFrame, pd.Series, dict, tuple, optional | ||
| Metadata describing the output DataFrame or Series. Should have |
There was a problem hiding this comment.
Suggest something like the following:
An empty pandas DataFrame or Series that matches the dtypes and column names of the output. Alternatively ...
Leading with the term metadata might be confusing to newcomers.
|
|
- `apply_concat_apply` now infers metadata if not provided - docstring description for `meta` parameter is shared between all functions that need it, through the use of a decorator - `map_partitions` function matches `map_partitions` method - Re-add `_pd` and `_pd_nonempty` attributes as deprecated properties - Deprecate `metadata` keyword to `dd.from_delayed`, replace with `meta`. Improve docstring for `meta` here. - a few docstring cleanups
|
Anything else here? Planning to merge later today if no comment. |
|
Nothing from me. +1 to merge |
After dask dask/dask#1422, dask dataframe mandates that all dask dataframes are fully typed. Previously `to_dask` wouldn't result in a fully typed dataframe, this fixes that.
These were xfailed in dask#1422, as the last release of castra was incompatible with the new metadata. This was fixed in blaze/castra#64, and a new release was made (0.1.8). We now only run these tests if castra version is >= 0.1.8
These were xfailed in #1422, as the last release of castra was incompatible with the new metadata. This was fixed in blaze/castra#64, and a new release was made (0.1.8). We now only run these tests if castra version is >= 0.1.8
This PR is an attempt to enforce that dask dataframes always know their full metadata (fixes #1209). Previously we allowed partial knowledge, with full dtype/column name computation done lazily if needed. This seemed like a good idea at the time, but masked many hidden metadata inference issues (functions could forget to pass along dtype, and we'd just recompute later). We also had to keep track of which bits of metadata were known, and which were unknown, resulting in frequent incorrect dtype inference.
Inference with pandas is much trickier than it is with numpy, as the dtype of the output series can change depending on values as well as input dtypes. Some functions also return different dtypes if a series is empty vs if it isn't. To get around this, a
_pd_nonemptyattribute is added to all_Frameobjects, which matches_pd's metadata, but contains one row of fake data. This helps for many situations, but not all.Todo:
apply,map_partitions, etc...