timeit on quick snippets causes UnicodeEncodeError

Bug #348466 reported by Stephan Peijnik
2
Affects Status Importance Assigned to Milestone
IPython
Fix Committed
Medium
Unassigned
ipython (Debian)
Fix Released
Unknown

Bug Description

This bug report came in via bugs.debian.org. It seems to be present in ipython 0.9.1.

Quoting the reporter's description of the bug:

Here is the snippet (although I guess it needs to be present on any quick but
not uber-quick function ;)) and output:

*In [2]:import scipy.stats
In [3]:import numpy as N
In [4]:cpaste
Pasting code; enter '--' alone on the line to stop.
:def cr():
: try:
: scipy.stats.rdist(1.32, 0, 1).cdf(-1.0+N.finfo(float).eps)
: except ZeroDivisionError:
: pass
:--

In [5]:timeit cr()
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)

/home/yoh/proj/pymvpa/pymvpa/mvpa/tests/<ipython console> in <module>()

/var/lib/python-support/python2.5/IPython/iplib.py in ipmagic(self, arg_s)
    951 else:
    952 magic_args = self.var_expand(magic_args,1)
--> 953 return fn(magic_args)
    954
    955 def ipalias(self,arg_s):

/var/lib/python-support/python2.5/IPython/Magic.py in magic_timeit(self, parameter_s)
   1829 precision,
   1830 best * scaling[order],
-> 1831 units[order])
   1832 if tc > tc_min:
   1833 print "Compiler time: %.2f s" % tc

UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 27: ordinal not in range(128)

Related branches

Changed in ipython:
status: Unknown → Confirmed
Revision history for this message
Henry Prêcheur (henry-precheur) wrote :

This is because the terminal doesn't support UTF-8. I have the same problem on OpenBSD with the stock xterm:

In [1]: print u'\xb5'
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)

/home/henry/<ipython console> in <module>()

UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 0: ordinal not in range(128)

I would advice to replace the u'\xb5s' with u'micros' since it can be displayed on every terminals.

Revision history for this message
Fernando Perez (fdo.perez) wrote :

http://bazaar.launchpad.net/~fdo.perez/ipython/trunk-dev/revision/1186

Contains a fix, though it's not ideal. I'd love to know how to do it so we don't lose the 'micro' character where it works. Input from unicode experts welcome.

Changed in ipython:
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Brian Granger (ellisonbg) wrote :

Should we call this "Fix Committed" or do you want to pursue further ways of resolving this?

Revision history for this message
Fernando Perez (fdo.perez) wrote :

Marking "Fix Committed", but I'd like to leave it without "Fix Released" in case we find a better solution.

Basically 'almost closed', but I'd like to have a better fix. I suspect once we start doing 3.0 work we'll have to revisit this and similar issues more closely.

Changed in ipython:
status: In Progress → Fix Committed
Changed in ipython (Debian):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.