quantopian / pyfolio

Portfolio and risk analytics in Python
https://quantopian.github.io/pyfolio
Apache License 2.0
5.69k stars 1.78k forks source link

AttributeError: type object 'Dataset' has no attribute 'unify_chunks' #663

Open yankoval opened 3 years ago

yankoval commented 3 years ago

Raised error when import pyfolio

example:

import pyfolio as pf

Please provide the full traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-1977abd82007> in <module>()
----> 1 import pyfolio as pf

/home/ivan/env-zipline/lib/python3.6/site-packages/pyfolio/__init__.py in <module>()
     11 from . import perf_attrib
     12 
---> 13 from .tears import *  # noqa
     14 from .plotting import *  # noqa
     15 from ._version import get_versions

/home/ivan/env-zipline/lib/python3.6/site-packages/pyfolio/tears.py in <module>()
     36 
     37 try:
---> 38     from . import bayesian
     39     have_bayesian = True
     40 except ImportError:

/home/ivan/env-zipline/lib/python3.6/site-packages/pyfolio/bayesian.py in <module>()
     22 import matplotlib.pyplot as plt
     23 
---> 24 import pymc3 as pm
     25 
     26 try:

/home/ivan/env-zipline/lib/python3.6/site-packages/pymc3/__init__.py in <module>()
     11 from .model_graph import model_to_graphviz
     12 from . import ode
---> 13 from .stats import *
     14 from .sampling import *
     15 from .step_methods import *

/home/ivan/env-zipline/lib/python3.6/site-packages/pymc3/stats/__init__.py in <module>()
      8 import warnings
      9 
---> 10 import arviz as az
     11 
     12 def map_args(func):

/home/ivan/env-zipline/lib/python3.6/site-packages/arviz/__init__.py in <module>()
     14 
     15 
---> 16 from .data import *
     17 from .plots import *
     18 from .plots import backends

/home/ivan/env-zipline/lib/python3.6/site-packages/arviz/data/__init__.py in <module>()
      1 """Code for loading and manipulating data structures."""
      2 from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array
----> 3 from .converters import convert_to_dataset, convert_to_inference_data
      4 from .datasets import clear_data_home, list_datasets, load_arviz_data
      5 from .inference_data import InferenceData, concat

/home/ivan/env-zipline/lib/python3.6/site-packages/arviz/data/converters.py in <module>()
      4 
      5 from .base import dict_to_dataset
----> 6 from .inference_data import InferenceData
      7 from .io_cmdstan import from_cmdstan
      8 from .io_cmdstanpy import from_cmdstanpy

/home/ivan/env-zipline/lib/python3.6/site-packages/arviz/data/inference_data.py in <module>()
     50 
     51 
---> 52 class InferenceData:
     53     """Container for inference data storage using xarray.
     54 

/home/ivan/env-zipline/lib/python3.6/site-packages/arviz/data/inference_data.py in InferenceData()
    857     sortby = _extend_xr_method(xr.Dataset.sortby)
    858     chunk = _extend_xr_method(xr.Dataset.chunk)
--> 859     unify_chunks = _extend_xr_method(xr.Dataset.unify_chunks)
    860     load = _extend_xr_method(xr.Dataset.load)
    861     compute = _extend_xr_method(xr.Dataset.compute)

AttributeError: type object 'Dataset' has no attribute 'unify_chunks'

Please provide any additional information below:

Versions

RichardDale commented 3 years ago

As time goes by, and various packages get updated on conda-forge, more things will break. Here's a workaround until some of these versions are baked in.

Whilst this comment is not a solution, it's certainly a workaround until someone revisits the exact inter-package dependencies.

Using an earlier version of some of the modules seems to fix things arviz v0.7.0 xarray v0.13.0 don't have this issue.

With a LOT of trial and error (probably about 30 virtual environments created), this combination seems to work OK, at least as at Dec 14 2020:

Here's exactly how we install our environments that works with all of our tests:

conda create -n zip36 python=3.6 conda activate zip36 conda install -c conda-forge zipline pyfolio matplotlib-base=3.0.3 xarray=0.13.0 arviz=0.7.0 theano=1.0.3 mkl-service m2w64-toolchain conda install jupyter matplotlib=3.0.3 pip install norgatedata zipline-norgatedata

Note that there are still several patches required to get futures to work correctly, mixed futures/equities bundles, backtesting calendar limits, and some other ugliness/warnings, which we've documented here: https://pypi.org/project/zipline-norgatedata/

Cheers, Richard.

yankoval commented 3 years ago

Thank you Richard. This solved the import problem. But unfortunately next problem appears: pyfolio reported about the problem with zipline.assets.