On Sat, Jul 28, 2012 at 8:04 AM, Ondřej Čertík <ondrej.cer...@gmail.com> wrote: > On Sat, Jul 28, 2012 at 7:58 AM, Ondřej Čertík <ondrej.cer...@gmail.com> > wrote: > [...] >> Here is the code in defchararray.py: >> >> >> 1911 if not _globalvar and self.dtype.char not in 'SUbc': >> 1912 raise ValueError("Can only create a chararray from >> string data.") >> 1913 >> 1914 def __getitem__(self, obj): >> 1915 val = ndarray.__getitem__(self, obj) >> 1916 -> if issubclass(val.dtype.type, character) and not _len(val) >> == 0: >> 1917 temp = val.rstrip() >> 1918 if _len(temp) == 0: >> 1919 val = '' >> 1920 else: >> 1921 val = temp >> >> >> and here is some debugging info: >> > > Python 3.3: > >> >> (Pdb) p self >> (Pdb) p obj >> (0, 0) >> (Pdb) p val >> 'abc' >> (Pdb) p type(val) >> <class 'str'> > > Python 3.2: > > (Pdb) p self > chararray([['abc', '123'], > ['789', 'xyz']], > dtype='<U3') > (Pdb) p obj > (0, 0) > (Pdb) p val > 'abc' > (Pdb) p type(val) > <class 'numpy.str_'> > > > So I think there might be some conversion issues int the chararray, > that instead of using numpy.str_, it uses Python's str. > Weird.
Ok, found this minimal example of the problem. Python 3.3: >>> from numpy import array >>> a = array(["123", "abc"]) >>> a array(['123', 'abc'], dtype='<U3') >>> a[0] '123' >>> type(a[0]) <class 'str'> Python 3.2: >>> from numpy import array >>> a = array(["123", "abc"]) >>> a array(['123', 'abc'], dtype='<U3') >>> a[0] '123' >>> type(a[0]) <class 'numpy.str_'> So at some point, the strings get converted to numpy strings in 3.2, but not in 3.3. Ondrej _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion