Skip to content

Better layer name synthesis for non-HLGs#5888

Merged
mrocklin merged 2 commits intodask:masterfrom
bmerry:fix-5850
Feb 14, 2020
Merged

Better layer name synthesis for non-HLGs#5888
mrocklin merged 2 commits intodask:masterfrom
bmerry:fix-5850

Conversation

@bmerry
Copy link
Contributor

@bmerry bmerry commented Feb 13, 2020

when a dependent collection passed to HighLevelGraph.from_collections
has a __dask_graph__ that is not a HighLevelGraph, the layer synthesised
for it was being named with id(). This caused problems, because there
are places in the code that assume that the layer name matches the key
names inside the layer (see #5850), and dask.array.utils._check_dsk
asserts that layer names are all tuples or strings, not integers.

Address withby naming the layer collection.__dask_layers__()[0],
falling back to the old behaviour if __dask_layers__ doesn't exist or
returns an empty tuple. I'm not sure what the ideal behaviour is if
__dask_layers__() returns more than one element. The built-in
collections (array, dataframe, bag and delayed) all return a singleton;
xarray's Dataset can return multiple values, but it also returns a
HighLevelGraph from __dask_graph__ so the issue doesn't arise.

Closes #5850.

  • Tests added / passed
  • Passes black dask / flake8 dask

When a dependent collection passed to HighLevelGraph.from_collections
has a __dask_graph__ that is not a HighLevelGraph, the layer synthesised
for it was being named with `id()`. This caused problems, because there
are places in the code that assume that the layer name matches the key
names inside the layer (see dask#5850), and dask.array.utils._check_dsk
asserts that layer names are all tuples or strings, not integers.

Address withby naming the layer `collection.__dask_layers__()[0]`,
falling back to the old behaviour if `__dask_layers__` doesn't exist or
returns an empty tuple.  I'm not sure what the ideal behaviour is if
`__dask_layers__()` returns more than one element. The built-in
collections (array, dataframe, bag and delayed) all return a singleton;
xarray's Dataset can return multiple values, but it also returns a
HighLevelGraph from `__dask_graph__` so the issue doesn't arise.

Closes dask#5850.
@bmerry bmerry requested a review from mrocklin February 13, 2020 10:42
@bmerry
Copy link
Contributor Author

bmerry commented Feb 13, 2020

There is a test failure (at least when it was tested on my branch), but it also appears to be failing on master.

else:
key = id(graph)
try:
key = collection.__dask_layers__()[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this just to assert that we're not accidentally dropping any information here? If this situation does arise (other collections exist) at least we'll fail more loudly.

Suggested change
key = collection.__dask_layers__()[0]
[key] = collection.__dask_layers__()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - done.

If a collection does not have a HighLevelGraph and we're using
`__dask_layers__` to pick a name to use to convert to a HighLevelGraph,
raise an error if there is not exactly one name in `__dask_layers__`,
rather than just taking the first one.
@mrocklin mrocklin merged commit 5db2881 into dask:master Feb 14, 2020
@mrocklin
Copy link
Member

Thanks @bmerry ! Merging in.

@bmerry bmerry deleted the fix-5850 branch February 17, 2020 10:56
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.

Dask array with non-highlevelgraph leads to KeyError

2 participants