pytorch-ts icon indicating copy to clipboard operation
pytorch-ts copied to clipboard

ImportError of 'maybe_len'

Open mrluin opened this issue 3 years ago • 2 comments

Hello,

I installed pytorchts by using command pip install pytorchts.

It occurs an ImportError when import maybe_len from gluonts.itertools

 from gluonts.itertools import maybe_len

Could you tell me how to solve this problem?

mrluin avatar Dec 25 '21 03:12 mrluin

https://ts.gluon.ai/_modules/gluonts/support/util.html#maybe_len

def maybe_len(obj) -> Optional[int]:
    try:
        return len(obj)
    except (NotImplementedError, AttributeError):
        return None

try this in pytorch-ts/pts/model/estimator.py:

# from gluonts.itertools import maybe_len
from gluonts.support.util import maybe_len

cjn-chen avatar Dec 28 '21 05:12 cjn-chen

So recently gluonts refactored this method in their master branch and so in preparation for this change, I also merged in a fix in pytorch-ts' master branch. If you are using the release version then you should not have an issue... else you might want to use the master branch of gluonts and pytorch-ts.

hope that helps!

kashif avatar Jan 10 '22 11:01 kashif