|
From: Lionel R. <lro...@li...> - 2009-01-05 15:06:18
|
Hi all,
Trying to write to text files some plotted datas, we have a strange
behavour on masked arrays after importing pylab, with the dot decimal
separator replaced by a comma (but not all) :
##############################
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> a=np.ma.array([1., 1.01, 2.11, 3.61])
>>> for i in a:str(i)
...
'1.0'
'1.01'
'2.11'
'3.61'
>>> import matplotlib
>>> for i in a:str(i)
...
'1.0'
'1.01'
'2.11'
'3.61'
>>> import pylab
>>> for i in a:str(i)
...
'1.0'
'1,01'
'2,11'
'3,61'
>>> np.__version__, matplotlib.__version__
('1.2.1', '0.98.3')
#############################
Any help welcomes!
--
Lionel Roubeyrie
chargé d'études
LIMAIR - La Surveillance de l'Air en Limousin
http://www.limair.asso.fr
|
|
From: Ryan M. <rm...@gm...> - 2009-01-05 15:18:21
|
Lionel Roubeyrie wrote: > Hi all, > Trying to write to text files some plotted datas, we have a strange > behavour on masked arrays after importing pylab, with the dot decimal > separator replaced by a comma (but not all) : > ############################## > Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) > [GCC 4.3.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. This has been reported before, and IIRC, it's a problem with PyGTK. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma |
|
From: Michael D. <md...@st...> - 2009-01-05 15:28:18
|
It's a bug with PyGTK in that merely importing it sets the locale. But more seriously, it's also a bug in Numpy, in that its string formatting is dependent on locale (unlike standard floats in Python). See this Numpy bug: http://projects.scipy.org/scipy/numpy/ticket/902 * *and this mailing list thread: http://www.mail-archive.com/num...@sc.../msg14563.html Cheers, Mike Ryan May wrote: > Lionel Roubeyrie wrote: > >> Hi all, >> Trying to write to text files some plotted datas, we have a strange >> behavour on masked arrays after importing pylab, with the dot decimal >> separator replaced by a comma (but not all) : >> ############################## >> Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >> [GCC 4.3.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> > > This has been reported before, and IIRC, it's a problem with PyGTK. > > Ryan > > -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
|
From: David C. <da...@ar...> - 2009-01-05 15:28:27
|
Hi Ryan, Ryan May wrote: > Lionel Roubeyrie wrote: > >> Hi all, >> Trying to write to text files some plotted datas, we have a strange >> behavour on masked arrays after importing pylab, with the dot decimal >> separator replaced by a comma (but not all) : >> ############################## >> Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49) >> [GCC 4.3.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> > > This has been reported before, and IIRC, it's a problem with PyGTK. > The fact that pygtk changes the local at import sounds buggy indeed, but numpy should not be dependent on the locale anyway, so it also shows a numpy bug I think: http://scipy.org/scipy/numpy/ticket/884 Pauli and other have been working on those locale-related bugs in numpy, but they are a bit fastidious to fix - hopefully, they will make their way into numpy 1.3 David |
|
From: Michael D. <md...@st...> - 2009-01-05 15:23:15
|
This seems to be a bug (or at least inconsistent behavior) in numpy when
the locale is set (which happens when gtk is imported -- replace 'import
pylab' with 'import gtk' and you'll see the same behavior).
We actually use a workaround for this in other parts of matplotlib,
which is:
for i in a: str(float(i))
By forcing the conversion to a Python float first, you can get around
the localized number output.
I'll follow up with this on the numpy bug tracker or mailing list, since
this has been a long-standing niggle of mine as well.
Cheers,
Mike
Lionel Roubeyrie wrote:
> Hi all,
> Trying to write to text files some plotted datas, we have a strange
> behavour on masked arrays after importing pylab, with the dot decimal
> separator replaced by a comma (but not all) :
> ##############################
> Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
>>>> import numpy as np
>>>> a=np.ma.array([1., 1.01, 2.11, 3.61])
>>>> for i in a:str(i)
>>>>
> ...
> '1.0'
> '1.01'
> '2.11'
> '3.61'
>
>>>> import matplotlib
>>>> for i in a:str(i)
>>>>
> ...
> '1.0'
> '1.01'
> '2.11'
> '3.61'
>
>>>> import pylab
>>>> for i in a:str(i)
>>>>
> ...
> '1.0'
> '1,01'
> '2,11'
> '3,61'
>
>>>> np.__version__, matplotlib.__version__
>>>>
> ('1.2.1', '0.98.3')
> #############################
>
> Any help welcomes!
>
>
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
|
|
From: Lionel R. <lro...@li...> - 2009-01-05 16:27:51
|
Thanks for your responses,
Looking comments in the tickets, putting
import locale
locale.setlocale(locale.LC_NUMERIC, 'C')
after the pylab import resolves the problem (but not the bug...).
Have a happy new year
Le lundi 05 janvier 2009 à 15:37 +0100, Lionel Roubeyrie a écrit :
> Hi all,
> Trying to write to text files some plotted datas, we have a strange
> behavour on masked arrays after importing pylab, with the dot decimal
> separator replaced by a comma (but not all) :
> ##############################
> Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy as np
> >>> a=np.ma.array([1., 1.01, 2.11, 3.61])
> >>> for i in a:str(i)
> ...
> '1.0'
> '1.01'
> '2.11'
> '3.61'
> >>> import matplotlib
> >>> for i in a:str(i)
> ...
> '1.0'
> '1.01'
> '2.11'
> '3.61'
> >>> import pylab
> >>> for i in a:str(i)
> ...
> '1.0'
> '1,01'
> '2,11'
> '3,61'
> >>> np.__version__, matplotlib.__version__
> ('1.2.1', '0.98.3')
> #############################
>
> Any help welcomes!
>
--
Lionel Roubeyrie
chargé d'études
LIMAIR - La Surveillance de l'Air en Limousin
http://www.limair.asso.fr
|