You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KeyError with set_index(col, npartitions="auto") when reading parquet #5893
Given that this seems to be an environment issue (we have different behavior in different environments) can I ask you to try this again in a minimal environment and then share that environment? Presumably this would be something like a very small conda environment.yaml file, or a simple conda create ... line.
/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/fastparquet/dataframe.py:5: FutureWarning: pandas.core.index is deprecated and will be removed in a future version. The public classes are available in the top-level namespace.
from pandas.core.index import CategoricalIndex, RangeIndex, Index, MultiIndex
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/dataframe/core.py", line 3557, in set_index**kwargs
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/dataframe/shuffle.py", line 66, in set_index
index2, df = base.optimize(index2, df)
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/base.py", line 368, in optimize
dsk = collections_to_dsk(collections, **kwargs)
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/base.py", line 219, in collections_to_dsk
[opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()],
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/base.py", line 219, in <listcomp>
[opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()],
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/dataframe/optimize.py", line 23, in optimize
dsk, dependencies = cull(dsk, list(core.flatten(keys)))
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/optimization.py", line 51, in cullfor k in work
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/optimization.py", line 51, in <listcomp>for k in work
File "/u02/users/wroach/.conda/envs/py37/lib/python3.7/site-packages/dask/core.py", line 187, in get_dependencies
arg = dsk[key]
KeyError: ('read-parquet-a2ab7bc7be12a8f455597b9bd8cb5f54', 1)
cc @TomAugspurger , I could use your advice here. This is due to optimize_read_parquet_getitem. The keys that are passed in to optimize include the keys of the read_parquet operation itself. So, after it gets optimized/transformed those keys are no longer around, and so things fail. Here is a smaller reproducer:
Activity
mrocklin commentedon Feb 16, 2020
I apologize for the delay in response @WesRoach
I tried your example (thank you for making a simple example) and it seems to work out ok for me
If you have time to provide a traceback that might help things. See https://blog.dask.org/2018/02/28/minimal-bug-reports
WesRoach commentedon Feb 17, 2020
@mrocklin Thanks for taking a look!
Traceback
Details
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-1-f74773a3e6b9> in <module> 20 ddf.set_index("C", npartitions=1) # Works 21 ddf.set_index("C") # Works ---> 22 ddf.set_index("C", npartitions="auto") # KeyError ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/dataframe/core.py in set_index(***failed resolving arguments***) 3555 npartitions=npartitions, 3556 divisions=divisions, -> 3557 **kwargs 3558 ) 3559 ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/dataframe/shuffle.py in set_index(df, index, npartitions, shuffle, compute, drop, upsample, divisions, partition_size, **kwargs) 64 if divisions is None: 65 if repartition: ---> 66 index2, df = base.optimize(index2, df) 67 parts = df.to_delayed(optimize_graph=False) 68 sizes = [delayed(sizeof)(part) for part in parts] ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/base.py in optimize(*args, **kwargs) 366 return args 367 --> 368 dsk = collections_to_dsk(collections, **kwargs) 369 postpersists = [ 370 a.__dask_postpersist__() if is_dask_collection(a) else (None, a) for a in args ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/base.py in collections_to_dsk(collections, optimize_graph, **kwargs) 217 *map( 218 ensure_dict, --> 219 [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()], 220 ) 221 ) ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/base.py in <listcomp>(.0) 217 *map( 218 ensure_dict, --> 219 [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()], 220 ) 221 ) ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/dataframe/optimize.py in optimize(dsk, keys, **kwargs) 21 22 if isinstance(keys, list): ---> 23 dsk, dependencies = cull(dsk, list(core.flatten(keys))) 24 else: 25 dsk, dependencies = cull(dsk, [keys]) ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/optimization.py in cull(dsk, keys) 49 deps = [ 50 (k, get_dependencies(dsk, k, as_list=True)) # fuse needs lists ---> 51 for k in work 52 ] 53 dependencies.update(deps) ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/optimization.py in <listcomp>(.0) 49 deps = [ 50 (k, get_dependencies(dsk, k, as_list=True)) # fuse needs lists ---> 51 for k in work 52 ] 53 dependencies.update(deps) ~/.conda/envs/hcdev-latest/lib/python3.7/site-packages/dask/core.py in get_dependencies(dsk, key, task, as_list) 185 """ 186 if key is not None: --> 187 arg = dsk[key] 188 elif task is not no_default: 189 arg = task KeyError: ('read-parquet-a2ab7bc7be12a8f455597b9bd8cb5f54', 0)conda list
Details
conda list --explicit
Details
mrocklin commentedon Feb 17, 2020
Given that this seems to be an environment issue (we have different behavior in different environments) can I ask you to try this again in a minimal environment and then share that environment? Presumably this would be something like a very small conda environment.yaml file, or a simple
conda create ...line.rileyschack commentedon Feb 17, 2020
Tested on Windows 10 with the following environment and getting the same
KeyErroras @WesRoach:conda list
Details
Traceback
Details
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-1-056ae696444b> in <module> 15 ddf.set_index("C", npartitions=1) # Works 16 ddf.set_index("C") # Works ---> 17 ddf.set_index("C", npartitions="auto") # KeyError C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\dataframe\core.py in set_index(***failed resolving arguments***) 3549 from .shuffle import set_index 3550 -> 3551 return set_index( 3552 self, 3553 other, C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\dataframe\shuffle.py in set_index(df, index, npartitions, shuffle, compute, drop, upsample, divisions, partition_size, **kwargs) 64 if divisions is None: 65 if repartition: ---> 66 index2, df = base.optimize(index2, df) 67 parts = df.to_delayed(optimize_graph=False) 68 sizes = [delayed(sizeof)(part) for part in parts] C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\base.py in optimize(*args, **kwargs) 366 return args 367 --> 368 dsk = collections_to_dsk(collections, **kwargs) 369 postpersists = [ 370 a.__dask_postpersist__() if is_dask_collection(a) else (None, a) for a in args C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\base.py in collections_to_dsk(collections, optimize_graph, **kwargs) 217 *map( 218 ensure_dict, --> 219 [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()], 220 ) 221 ) C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\base.py in <listcomp>(.0) 217 *map( 218 ensure_dict, --> 219 [opt(dsk, keys, **kwargs) for opt, (dsk, keys) in groups.items()], 220 ) 221 ) C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\dataframe\optimize.py in optimize(dsk, keys, **kwargs) 21 22 if isinstance(keys, list): ---> 23 dsk, dependencies = cull(dsk, list(core.flatten(keys))) 24 else: 25 dsk, dependencies = cull(dsk, [keys]) C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\optimization.py in cull(dsk, keys) 47 new_work = [] 48 out_keys += work ---> 49 deps = [ 50 (k, get_dependencies(dsk, k, as_list=True)) # fuse needs lists 51 for k in work C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\optimization.py in <listcomp>(.0) 48 out_keys += work 49 deps = [ ---> 50 (k, get_dependencies(dsk, k, as_list=True)) # fuse needs lists 51 for k in work 52 ] C:\bit9prog\dev\anaconda3\envs\test-bug\lib\site-packages\dask\core.py in get_dependencies(dsk, key, task, as_list) 185 """ 186 if key is not None: --> 187 arg = dsk[key] 188 elif task is not no_default: 189 arg = task KeyError: ('read-parquet-a2ab7bc7be12a8f455597b9bd8cb5f54', 0)WesRoach commentedon Feb 17, 2020
Linux:
conda create -n py37 python=3.7 dask fastparquetconda list
Details
Traceback
Details
mrocklin commentedon Feb 18, 2020
Thanks @WesRoach , that's quite helpful.
cc @TomAugspurger , I could use your advice here. This is due to
optimize_read_parquet_getitem. The keys that are passed in tooptimizeinclude the keys of the read_parquet operation itself. So, after it gets optimized/transformed those keys are no longer around, and so things fail. Here is a smaller reproducer:My sense here is that we should not optimize out the read_parquet + getitem layer if the layer is any of the output keys.
Any thoughts on this?
Skip parquet getitem optimization for some keys
Skip parquet getitem optimization for some keys (#5917)