Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str(tick library) fails in IPython #49

Closed
eeaston opened this issue Nov 13, 2015 · 2 comments · Fixed by #74
Closed

str(tick library) fails in IPython #49

eeaston opened this issue Nov 13, 2015 · 2 comments · Fixed by #74

Comments

@eeaston
Copy link
Contributor

eeaston commented Nov 13, 2015

When stringifying a library object, it blows up in IPython:

In [38]: tickdb = Arctic('database_name')
In [39]: tickdb['library_name']
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/ipython-3.2.0_1_ahl1-py2.7.egg/IPython/core/formatters.pyc in __call__(self, obj)
    688                 type_pprinters=self.type_printers,
    689                 deferred_pprinters=self.deferred_printers)
--> 690             printer.pretty(obj)
    691             printer.flush()
    692             return stream.getvalue()

/ipython-3.2.0_1_ahl1-py2.7.egg/IPython/lib/pretty.pyc in pretty(self, obj)
    407                             if callable(meth):
    408                                 return meth(obj, self, cycle)
--> 409             return _default_pprint(obj, self, cycle)
    410         finally:
    411             self.end_group()

/ipython-3.2.0_1_ahl1-py2.7.egg/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    527     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    528         # A user-provided repr. Find newlines and replace them with p.break_()
--> 529         _repr_pprint(obj, p, cycle)
    530         return
    531     p.begin_group(1, '<')

/ipython-3.2.0_1_ahl1-py2.7.egg/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
    709     """A pprint that just redirects to the normal repr function."""
    710     # Find newlines and replace them with p.break_()
--> 711     output = repr(obj)
    712     for idx,output_line in enumerate(output.splitlines()):
    713         if idx:

/arctic/tickstore/tickstore.py in __repr__(self)
    107 
    108     def __repr__(self):
--> 109         return str(self)
    110 
    111     def delete(self, symbol, date_range=None):

/arctic/tickstore/tickstore.py in __str__(self)
    104     def __str__(self):
    105         return """<%s at %s>
--> 106 %s""" % (self.__class__.__name__, hex(id(self)), indent(str(self._arctic_lib), 4))
    107 
    108     def __repr__(self):

NameError: global name 'indent' is not defined
@femtotrader
Copy link
Contributor

I think something like

from .._util import indent

is missing...

@femtotrader
Copy link
Contributor

Full code to reproduce problem is:

In [1]: from arctic import Arctic
In [2]: store = Arctic('localhost')
In [3]: store.initialize_library('library_name', 'TickStoreV3')
In [4]: store['library_name']
Out[4]: ---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
//anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    695                 type_pprinters=self.type_printers,
    696                 deferred_pprinters=self.deferred_printers)
--> 697             printer.pretty(obj)
    698             printer.flush()
    699             return stream.getvalue()

//anaconda/envs/py27/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    381                             if callable(meth):
    382                                 return meth(obj, self, cycle)
--> 383             return _default_pprint(obj, self, cycle)
    384         finally:
    385             self.end_group()

//anaconda/envs/py27/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    501     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    502         # A user-provided repr. Find newlines and replace them with p.break_()
--> 503         _repr_pprint(obj, p, cycle)
    504         return
    505     p.begin_group(1, '<')

//anaconda/envs/py27/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
    683     """A pprint that just redirects to the normal repr function."""
    684     # Find newlines and replace them with p.break_()
--> 685     output = repr(obj)
    686     for idx,output_line in enumerate(output.splitlines()):
    687         if idx:

//anaconda/envs/py27/lib/python2.7/site-packages/arctic/tickstore/tickstore.pyc in __repr__(self)
    107
    108     def __repr__(self):
--> 109         return str(self)
    110
    111     def delete(self, symbol, date_range=None):

//anaconda/envs/py27/lib/python2.7/site-packages/arctic/tickstore/tickstore.pyc in __str__(self)
    104     def __str__(self):
    105         return """<%s at %s>
--> 106 %s""" % (self.__class__.__name__, hex(id(self)), indent(str(self._arctic_lib), 4))
    107
    108     def __repr__(self):

NameError: global name 'indent' is not defined

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 a pull request may close this issue.

2 participants