dask-contrib / dask-histogram

Histograms with task scheduling.
https://dask-histogram.readthedocs.io
BSD 3-Clause "New" or "Revised" License
23 stars 4 forks source link

[fix]Solve circular import #151

Closed martindurant closed 2 months ago

martindurant commented 2 months ago

Fixes #149

This is a more complex way of solving things, by splitting this into two packages.

lgray commented 2 months ago

Hmmm still brings up the same problem :-/

martindurant commented 2 months ago

These fail because they use the released version of dask-awkward

lgray commented 2 months ago

indeed - I should look at these things after coffee.

Otherwise lgtm.

martindurant commented 2 months ago

OK, release is out on pypi and things are importable again.

lgray commented 2 months ago

Something's gone off with with the tests and optimization. One of the awkward histogram filling tests should be using the optimization function from dask awkward as opposed to dask histogram and now it has stopped doing that.

martindurant commented 2 months ago

I don't understand. This is a new issue? No code changed here...

lgray commented 2 months ago

Yeah I am not sure, but tests in main are failing.

I'll check on my laptop in a bit.

lgray commented 2 months ago

The tests even passed in your PR so that's rather strange!

martindurant commented 2 months ago

https://github.com/dask-contrib/dask-histogram/actions/runs/10946251458/job/30392316434?pr=152#step:5:138 you seem to be right. I have it locally too, must have been a different commit, though.

martindurant commented 2 months ago

OK, so the case is: dask is no longer auto-importing dask-awkward as before. If you import dask-awkward before running the graph, it is right. This was the point! dask-histogram uses the existence of "awkward" in the dask config to see whether dak has been imported, and then sets the optimise method. We can use importlib instead.

martindurant commented 2 months ago
--- a/src/dask_histogram/core.py
+++ b/src/dask_histogram/core.py
@@ -524,7 +524,9 @@ def _get_optimization_function():
     # running this optimization even in cases where it's unncessary
     # because if no AwkwardInputLayers from dask-awkward are
     # detected then the original graph is returned unchanged.
-    if dask.config.get("awkward", default=False):
+    import importlib.metadata
+
+    if importlib.metadata.distribution("dask_awkward"):
         from dask_awkward.lib.optimize import all_optimizations

OK?