src-d / modelforge

Python library to share machine learning models easily and reliably.
Apache License 2.0
18 stars 13 forks source link

DocumentFrequencies model from sourced/ml broke when imported in the IPython environment #17

Closed warenlg closed 6 years ago

warenlg commented 6 years ago

Using modelforge-0.5.1a0 in jupyter notebook 5.0.0

When importing DocumentFrequencies model from sourced/ml in jupyter notebook:

from sourced.ml.models.df import DocumentFrequencies
DocumentFrequencies()

had the error:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/IPython/core/formatters.py in __call__(self, obj)
    691                 type_pprinters=self.type_printers,
    692                 deferred_pprinters=self.deferred_printers)
--> 693             printer.pretty(obj)
    694             printer.flush()
    695             return stream.getvalue()

/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in pretty(self, obj)
    378                             if callable(meth):
    379                                 return meth(obj, self, cycle)
--> 380             return _default_pprint(obj, self, cycle)
    381         finally:
    382             self.end_group()

/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
    493     if _safe_getattr(klass, '__repr__', None) is not object.__repr__:
    494         # A user-provided repr. Find newlines and replace them with p.break_()
--> 495         _repr_pprint(obj, p, cycle)
    496         return
    497     p.begin_group(1, '<')

/usr/local/lib/python3.5/dist-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    691     """A pprint that just redirects to the normal repr function."""
    692     # Find newlines and replace them with p.break_()
--> 693     output = repr(obj)
    694     for idx,output_line in enumerate(output.splitlines()):
    695         if idx:

/usr/local/lib/python3.5/dist-packages/modelforge/model.py in __repr__(self)
    150     created_at = metaprop("created_at")
    151     version = metaprop("version")
--> 152     parent = metaprop("parent")
    153     license = metaprop("license")
    154 

AttributeError: module '__main__' has no attribute '__file__'
vmarkovtsev commented 6 years ago

This is a bug inside Model.__repr__(): the freshly created object misses some attributes. Please fix it and PR.

warenlg commented 6 years ago

https://github.com/src-d/modelforge/pull/18 merged