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

Already on GitHub? Sign in to your account

psearch: TypeError: expected string or buffer #129

yarikoptic opened this Issue Jun 21, 2010 · 3 comments


None yet
2 participants

yarikoptic commented Jun 21, 2010

version: 0.10-2 (Debian sid)
original report: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=565351

I've ran into this issue many times and finally decided to report ;)

In [1]: import numpy

In [2]: %psearch numpy._._s

TypeError Traceback (most recent call last)


/usr/lib/pymodules/python2.5/IPython/wildcard.pyc in glob_filter(lista, name_pattern, hidehidden, ignore_case)
113 else:
114 reg=re.compile(pattern+"$")
--> 115 result=[x for x in lista if reg.match(x) and show_hidden(x,hidehidden)]
116 return result
117 ns=self._ns

TypeError: expected string or buffer

happens with
ipdb> p lista
[<type 'numpy.void'>, <type 'numpy.float128'>, 'f4', <type 'numpy.int8'>, 'f8', <type 'numpy.float64'>, 'Complex128', <type 'numpy.int32'>, <type 'numpy.int16'>, 'Bool', 'b1', <type 'numpy.string_'>, 'String0', 'q', <type 'numpy.complex64'>, 'Complex64', 'G', 'u4', <type 'numpy.int64'>, 'Unicode0', 'u1', <type 'numpy.complex128'>, 'u2', 'i1', 'UInt16', 'Float32', <type 'numpy.int64'>, 'Int64', <type 'numpy.complex256'>, 'c16', '?', 'Void0', <type 'numpy.bool_'>, 'i8', <type 'numpy.uint8'>, 'B', 'D', <type 'numpy.object_'>, 'F', 'I', 'H', 'i2', <type 'numpy.uint16'>, 'L', 'O', 'i4', 'Q', 'S', 'c8', 'U', 'Int8', 'Complex32', 'V', <type 'numpy.uint32'>, <type 'numpy.unicode_'>, 'u8', 'UInt64', 'Float64', 'b', 'd', 'g', 'f', 'i', 'h', 'UInt8', 'l', 'UInt32', 'Object0', <type 'numpy.uint64'>, 'Float128', <type 'numpy.uint64'>, 'c32', 'f16', 'Int16', <type 'numpy.float32'>, 'Int32']

ipdb> reg.match(lista[0])
*** TypeError: expected string or buffer

I guess safest way would be to check first if x is a string at all ;)


takluyver commented Jan 11, 2011

Right, from the debian bug report, the command that triggered this is %psearch numpy.*.*s, although it's been mangled by the formatting here. The simplest way to replicate is:

a = {1:""}
%psearch a.*

Specifically, the problem is in utils.wildcard. When instantiating a NameSpace, objects are inspected by the dir2 function to produce a dictionary of their attributes. Dictionaries, however, are special cased, since the main namespaces are passed as dictionaries; they are used directly, rather than listing their attributes. So it's wrong whenever it constructs a namespace for a dictionary, but it will only throw an error if the dictionary has non-string keys.

I'm attempting to find an elegant solution.


takluyver commented Jan 11, 2011

The test, the fix, and the general tidy-up of the IPython.utils.wildcard module are in a sequence of commits at:


takluyver commented Feb 23, 2011

Merge branch 'issue-129'

closed by 26fb955
closed by 26fb955

markvoorhies pushed a commit to markvoorhies/ipython that referenced this issue Apr 21, 2011

minrk pushed a commit to minrk/ipython that referenced this issue Jul 1, 2013

Merge pull request #129 from minrk/fixcwd
allow nbconvert to run from anywhere

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment