Unexpected behaviour from timeseries.filled (in Python 2.7)
It seems something in Python 2.7 / Numpy 1.5 (or my Python 2.7 installation) is breaking scikits.timeseries.filled import scikits.timeseries from numpy import array t3 = scikits.timeseries.time_series(array([0.]), mask=[True],dates=['2010-Aug'],freq='M') t3.fill_value= 0. print(t3) print(t3.data) print(t3.fill_value) print(t3.filled()) # It seems it ignores the fill_value parameter print(t3.filled(0.)) In Python 2.6 this outputs c:\python26\python scikits_bug.py [--] [ 0.] 0.0 [ 0.] [ 0.] , but in Python 2.7 I get: c:\python27\python scikits_bug.py [--] [ 0.] 0.0 [ 1.00000000e+20] # This must be wrong! [ 0.] Python 2.6: scikits.timeseries version 0.91.3, numpy 1.3.0 Python 2.7: scikits.timeseries version 0.91.3, numpy 1.5.0 -- Åsmund Hjulstad, asmund@hjulstad.com
2010/9/6 Åsmund Hjulstad <asmund.hjulstad@gmail.com>:
It seems something in Python 2.7 / Numpy 1.5 (or my Python 2.7 installation) is breaking scikits.timeseries.filled
import scikits.timeseries from numpy import array t3 = scikits.timeseries.time_series(array([0.]), mask=[True],dates=['2010-Aug'],freq='M') t3.fill_value= 0. print(t3) print(t3.data) print(t3.fill_value) print(t3.filled()) # It seems it ignores the fill_value parameter print(t3.filled(0.))
, but in Python 2.7 I get: c:\python27\python scikits_bug.py [--] [ 0.] 0.0 [ 1.00000000e+20] # This must be wrong! [ 0.]
After some debugging, I found out the following: the TimeSeries.filled() method does this: result = self._series.filled(fill_value=fill_value).view(type(self)) somehow, the _series view does not retain the fill value. replacing this with (around line 1217 in tseries.py) result = MaskedArray.filled(self,fill_value=fill_value).view(type(self)) things work better (for me, at least) Regards, Åsmund Hjulstad
On Sep 6, 2010, at 5:32 PM, Åsmund Hjulstad wrote:
After some debugging, I found out the following:
the TimeSeries.filled() method does this:
result = self._series.filled(fill_value=fill_value).view(type(self))
somehow, the _series view does not retain the fill value.
replacing this with (around line 1217 in tseries.py)
result = MaskedArray.filled(self,fill_value=fill_value).view(type(self))
things work better (for me, at least)
Åsmund, Glad you were able to figure it out by yourself (and showing me where th pb was). Nevertheless, do you mind opening a ticket ? I have quite a few to process first, and I don't want this one to fall between the cracks. Thanks a lot in advance. P.
2010/9/6 Pierre GM <pgmdevlist@gmail.com>:
On Sep 6, 2010, at 5:32 PM, Åsmund Hjulstad wrote:
After some debugging, I found out the following: the TimeSeries.filled() method does this: result = self._series.filled(fill_value=fill_value).view(type(self)) somehow, the _series view does not retain the fill value. replacing this with (around line 1217 in tseries.py) result = MaskedArray.filled(self,fill_value=fill_value).view(type(self)) things work better (for me, at least)
Åsmund, Glad you were able to figure it out by yourself (and showing me where th pb was). Nevertheless, do you mind opening a ticket ? I have quite a few to process first, and I don't want this one to fall between the cracks. Thanks a lot in advance.
I will, one question though: Why does MaskedArray reset the fill_value when creating a view? This, appearantly, is what happens when the self._series property is accessed. Isn't it more reasonable to preserve it? I haven't been able to pinpoint what exactly caused the behaviour to change, whether it was the Numpy 1.3 -> 1.5 change or the Python 2.6 -> 2.7 (I would guess the former, though.) Ticket #105 created. http://projects.scipy.org/scikits/ticket/105
On Sep 6, 2010, at 7:37 PM, Åsmund Hjulstad wrote:
2010/9/6 Pierre GM <pgmdevlist@gmail.com>:
On Sep 6, 2010, at 5:32 PM, Åsmund Hjulstad wrote:
After some debugging, I found out the following: the TimeSeries.filled() method does this: result = self._series.filled(fill_value=fill_value).view(type(self)) somehow, the _series view does not retain the fill value. replacing this with (around line 1217 in tseries.py) result = MaskedArray.filled(self,fill_value=fill_value).view(type(self)) things work better (for me, at least)
Åsmund, Glad you were able to figure it out by yourself (and showing me where th pb was). Nevertheless, do you mind opening a ticket ? I have quite a few to process first, and I don't want this one to fall between the cracks. Thanks a lot in advance.
I will, one question though: Why does MaskedArray reset the fill_value when creating a view?
It does, but it shouldn't.
This, appearantly, is what happens when the self._series property is accessed. Isn't it more reasonable to preserve it? I haven't been able to pinpoint what exactly caused the behaviour to change, whether it was the Numpy 1.3 -> 1.5 change or the Python 2.6 -> 2.7 (I would guess the former, though.)
Probably the former indeed. OK, I'll be on that. Thx for the report !
participants (2)
-
Pierre GM -
Åsmund Hjulstad