Broadcasting TimeSeries

Discussion in 'Python' started by Davide Dalmasso, Sep 4, 2013.

  1. Hello,

    I opened my Python Shell and I wrote the following:

    >>> import numpy as np
    >>> import pandas as pd


    then I made a function

    >>> def afunc(aframe):

    return aframe - aframe.mean(axis=1)

    and I defined a DataFrame with time as index

    >>> A = pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5))
    >>> A

    a b c
    1984-12-20 -0.257916 -0.137923 -0.669796
    1984-12-21 -1.632874 -1.850365 1.571715
    1984-12-22 1.185828 -0.149839 -1.565930
    1984-12-23 -0.757311 0.034627 0.794608
    1984-12-24 0.548785 -1.126786 -0.438457

    now, if I call the function the following error is generated:

    >>> afunc(A)

    Traceback (most recent call last):
    File "<pyshell#6>", line 1, in <module>
    afunc(A)
    File "<pyshell#3>", line 2, in afunc
    return aframe - aframe.mean(axis=1)
    File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f
    return self._combine_series(other, na_op, fill_value, axis, level)
    File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in _combine_series
    return self._combine_series_infer(other, func, fill_value)
    File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in _combine_series_infer
    FutureWarning)
    File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
    file.write(warnings.formatwarning(message, category, filename,
    AttributeError: 'NoneType' object has no attribute 'write'

    then I recall the same function (without any change) and the function works!

    >>> afunc(A)

    a b c
    1984-12-20 0.097295 0.217289 -0.314584
    1984-12-21 -0.995699 -1.213190 2.208890
    1984-12-22 1.362475 0.026808 -1.389283
    1984-12-23 -0.781285 0.010652 0.770633
    1984-12-24 0.887604 -0.787967 -0.099637

    Why does this happen? Why I must call the function two times before it finally works?
    How can I overcome this problem?

    Many thanks in advance

    Davide
     
    Davide Dalmasso, Sep 4, 2013
    #1
    1. Advertising

  2. Davide Dalmasso

    Terry Reedy Guest

    On 9/4/2013 4:06 PM, Davide Dalmasso wrote:

    > I opened my Python Shell and I wrote the following:


    This is with Idle. I believe you are running on Windows.

    >>>> import numpy as np
    >>>> import pandas as pd

    >
    > then I made a function
    >
    >>>> def afunc(aframe):

    > return aframe - aframe.mean(axis=1)
    >
    > and I defined a DataFrame with time as index
    >
    >>>> A = pd.DataFrame(np.random.randn(5,3),columns=['a','b','c'],index=pd.date_range(start='1984-12-20',periods=5))
    >>>> A

    > a b c
    > 1984-12-20 -0.257916 -0.137923 -0.669796
    > 1984-12-21 -1.632874 -1.850365 1.571715
    > 1984-12-22 1.185828 -0.149839 -1.565930
    > 1984-12-23 -0.757311 0.034627 0.794608
    > 1984-12-24 0.548785 -1.126786 -0.438457
    >
    > now, if I call the function the following error is generated:
    >
    >>>> afunc(A)

    > Traceback (most recent call last):
    > File "<pyshell#6>", line 1, in <module>
    > afunc(A)
    > File "<pyshell#3>", line 2, in afunc
    > return aframe - aframe.mean(axis=1)
    > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 217, in f
    > return self._combine_series(other, na_op, fill_value, axis, level)
    > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3601, in _combine_series
    > return self._combine_series_infer(other, func, fill_value)
    > File "C:\Python33\lib\site-packages\pandas\core\frame.py", line 3619, in _combine_series_infer
    > FutureWarning)
    > File "C:\Python33\lib\idlelib\PyShell.py", line 60, in idle_showwarning
    > file.write(warnings.formatwarning(message, category, filename,
    > AttributeError: 'NoneType' object has no attribute 'write'


    This was a bug in Idle when run directly on Windows, from Start or an
    icon. In this circumstance, there is no stderr stream to write to. I
    fixed it last June by catching the AttributeError and ignoring the
    warning. The fix will be in the next 2.7 and 3.3 releases and is in the
    3.4 releases (currently 0a1, soon 0a2).

    The problem (of no stderr) is avoided now, while still using Idle, by
    starting Idle from a Command Prompt window (Start/Accessories):
    python -m idlelib
    or by starting the standard interpreter (from Start or icon) and entering
    >>> import idlelib.idle


    > then I recall the same function (without any change) and the function works!


    pandas must have a mechanism to only issue the warning once.

    >>>> afunc(A)

    > a b c
    > 1984-12-20 0.097295 0.217289 -0.314584
    > 1984-12-21 -0.995699 -1.213190 2.208890
    > 1984-12-22 1.362475 0.026808 -1.389283
    > 1984-12-23 -0.781285 0.010652 0.770633
    > 1984-12-24 0.887604 -0.787967 -0.099637
    >
    > Why does this happen? Why I must call the function two times before it finally works?
    > How can I overcome this problem?


    Answered, I believe.

    --
    Terry Jan Reedy
     
    Terry Reedy, Sep 4, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valentin tihomirov

    broadcasting a signal

    valentin tihomirov, Sep 22, 2004, in forum: VHDL
    Replies:
    11
    Views:
    769
    Jim Lewis
    Sep 23, 2004
  2. Tintifax

    installing scikits.timeseries

    Tintifax, Dec 23, 2010, in forum: Python
    Replies:
    0
    Views:
    493
    Tintifax
    Dec 23, 2010
  3. JB
    Replies:
    1
    Views:
    374
    Vlastimil Brom
    Jul 21, 2011
  4. Peter Booth

    Ruby/MySQL/Rails timeseries QN

    Peter Booth, Nov 10, 2006, in forum: Ruby
    Replies:
    0
    Views:
    141
    Peter Booth
    Nov 10, 2006
  5. Rob Redmon

    gnuplot timeseries

    Rob Redmon, Apr 22, 2009, in forum: Ruby
    Replies:
    2
    Views:
    218
    Rob Redmon
    Apr 22, 2009
Loading...

Share This Page