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

psearch: TypeError: expected string or buffer #129

Closed
yarikoptic opened this issue Jun 21, 2010 · 3 comments
Closed

psearch: TypeError: expected string or buffer #129

yarikoptic opened this issue Jun 21, 2010 · 3 comments
Milestone

Comments

@yarikoptic
Copy link
Contributor

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
Copy link
Member

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
Copy link
Member

The test, the fix, and the general tidy-up of the IPython.utils.wildcard module are in a sequence of commits at:
https://github.com/takowl/ipython/tree/issue-129

@takluyver
Copy link
Member

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
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants