Example #1
0
    def test_resample_median_bug_1688(self):
        df = DataFrame([1, 2], index=[datetime(2012, 1, 1, 0, 0, 0), datetime(2012, 1, 1, 0, 5, 0)])

        result = df.resample("T", how=lambda x: x.mean())
        exp = df.asfreq("T")
        tm.assert_frame_equal(result, exp)

        result = df.resample("T", how="median")
        exp = df.asfreq("T")
        tm.assert_frame_equal(result, exp)
Example #2
0
    def test_resample_median_bug_1688(self):

        for dtype in ["int64", "int32", "float64", "float32"]:
            df = DataFrame([1, 2], index=[datetime(2012, 1, 1, 0, 0, 0), datetime(2012, 1, 1, 0, 5, 0)], dtype=dtype)

            result = df.resample("T", how=lambda x: x.mean())
            exp = df.asfreq("T")
            tm.assert_frame_equal(result, exp)

            result = df.resample("T", how="median")
            exp = df.asfreq("T")
            tm.assert_frame_equal(result, exp)
Example #3
0
def test_resample_median_bug_1688():

    for dtype in ['int64', 'int32', 'float64', 'float32']:
        df = DataFrame([1, 2], index=[datetime(2012, 1, 1, 0, 0, 0),
                                      datetime(2012, 1, 1, 0, 5, 0)],
                       dtype=dtype)

        result = df.resample("T").apply(lambda x: x.mean())
        exp = df.asfreq('T')
        tm.assert_frame_equal(result, exp)

        result = df.resample("T").median()
        exp = df.asfreq('T')
        tm.assert_frame_equal(result, exp)
Example #4
0
 def test_dataframe(self):
     bts = DataFrame({'a': tm.makePeriodSeries()})
     ts = bts.asfreq('D')
     ax = bts.plot()
     self.assert_(ax.get_lines()[0].get_xydata()[0, 0], ts.index[0].ordinal)
     idx = ax.get_lines()[0].get_xdata()
     self.assert_(idx.freqstr == 'D')
Example #5
0
    def test_asfreq_datetimeindex(self):
        df = DataFrame({"A": [1, 2, 3]}, index=[datetime(2011, 11, 1), datetime(2011, 11, 2), datetime(2011, 11, 3)])
        df = df.asfreq("B")
        tm.assertIsInstance(df.index, DatetimeIndex)

        ts = df["A"].asfreq("B")
        tm.assertIsInstance(ts.index, DatetimeIndex)
Example #6
0
    def test_asfreq_datetimeindex(self):
        df = DataFrame({'A': [1, 2, 3]},
                       index=[datetime(2011, 11, 1), datetime(2011, 11, 2),
                              datetime(2011, 11, 3)])
        df = df.asfreq('B')
        assert isinstance(df.index, DatetimeIndex)

        ts = df['A'].asfreq('B')
        assert isinstance(ts.index, DatetimeIndex)
Example #7
0
    def test_asfreq_ts(self):
        index = PeriodIndex(freq='A', start='1/1/2001', end='12/31/2010')
        ts = Series(np.random.randn(len(index)), index=index)
        df = DataFrame(np.random.randn(len(index), 3), index=index)

        result = ts.asfreq('D', how='end')
        df_result = df.asfreq('D', how='end')
        exp_index = index.asfreq('D', how='end')
        assert len(result) == len(ts)
        tm.assert_index_equal(result.index, exp_index)
        tm.assert_index_equal(df_result.index, exp_index)

        result = ts.asfreq('D', how='start')
        assert len(result) == len(ts)
        tm.assert_index_equal(result.index, index.asfreq('D', how='start'))
Example #8
0
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict

plt.interactive(True)
names = ['AAPL', 'GOOG', 'MSFT', 'DELL', 'GS', 'MS', 'BAC', 'C']


def get_px(stock, start, end):
    print('Get ' + stock)
    return web.get_data_yahoo(stock, start, end)['Adj Close']


px = DataFrame({n: get_px(n, '1/1/2009', '6/1/2012') for n in names})

px = px.asfreq('B').fillna(method='pad')
rets = px.pct_change()
((1 + rets).cumprod() - 1).plot()
print('block')


def calc_mom(price, lookback, lag):
    mon_ret = price.shift(lag).pct_change(lookback)
    ranks = mon_ret.rank(axis=1, ascending=False)
    demeaned = ranks - ranks.mean(axis=1)
    return demeaned / demeaned.std(axis=1)


compound = lambda x: (1 + x).prod() - 1
daily_sr = lambda x: x.mean() / x.std()
Example #9
0
if __name__ == '__main__':
    fp, trace = parse_file(FILEPATH)

    # duration
    total_duration = trace.duration if not INTERVAL else INTERVAL.duration

    # Thermal
    NAMES = [TSENS_ALIAS[tsens] for tsens in trace.thermal.names if tsens in TSENS_ALIAS] + CLKS
    df_therm = DataFrame(columns=NAMES)
    for tsens in trace.thermal.names:
        for therm in trace.thermal.temp_intervals(tsens=tsens, interval=INTERVAL):
            df_therm.loc[start + Micro(therm.interval.start*1e6), TSENS_ALIAS[tsens]] = therm.temp

    # lets look at clocks.
    for clk in CLKS:
        for freq_event in trace.clock.frequency_intervals(clock=clk, interval=INTERVAL):
            i_start=start + Micro(freq_event.interval.start*1e6)
            i_end=start + Micro(freq_event.interval.end*1e6)
            try:
                df_therm.loc[i_start:i_end, clk] = freq_event.frequency
            except KeyError:
                print "Error logging " + str(freq_event)
                df_therm[start + Micro(freq_event.interval.start*1e6):start + Micro(freq_event.interval.end*1e6), clk] = freq_event.frequency
        for clk_event in trace.clock.clock_intervals(clock=clk, state=ftrace.clock.ClockState.DISABLED, interval=INTERVAL):
            df_therm.loc[start + Micro(clk_event.interval.start*1e6): start + Micro(clk_event.interval.end*1e6), clk] = 0

    df_therm.sort(inplace=True)
    df_therm = df_therm.asfreq(THERMAL_TIMELINE_RESOLUTION, method='ffill').fillna(method='ffill').fillna(-1)
    df_therm.to_csv(r'{C:\Users\c00759961\Documents\Charters\congitive-thermal-engine\res\thermal_timeline.csv')
Example #10
0
}

CLKS =['a57_clk', 'a53_clk', 'oxili_gfx3d_clk']

trace = Ftrace(r'C:\Users\c00759961\Documents\temp\nina-MDA35B-camera-UHD-recording-after.html', 
               ['tsens_read', 'tsens_threshold_clear', 'tsens_threshold_hit', 
                'clock_set_rate', 'clock_enable', 'clock_disable'])
   
start = Timestamp('1/1/1970')
#end = start + Second(trace.duration)

NAMES = [TSENS_ALIAS[tsens] for tsens in trace.thermal.names if tsens in TSENS_ALIAS] + CLKS
df_therm = DataFrame(columns=NAMES)
#index=period_range(start=start, end=end, freq='1U')
for tsens in trace.thermal.names:
    for therm in trace.thermal.temp_intervals(tsens=tsens):
        df_therm.loc[start + Micro(therm.interval.end*1e6), TSENS_ALIAS[tsens]] = therm.temp

# lets look at clocks.
for clk in CLKS:
    for freq_event in trace.clock.frequency_intervals(clock=clk):
        df_therm.loc[start + Micro(freq_event.interval.end*1e6), clk] = freq_event.frequency

    for clk_event in trace.clock.clock_intervals(clock=clk, 
                                                 state=ftrace.clock.ClockState.DISABLED):
        df_therm.loc[start + Micro(clk_event.interval.end*1e6), clk] = 0
        
df_therm.sort(inplace=True)
# Resample to every 100milliseconds
df_therm = df_therm.asfreq('100L', method='ffill').fillna(method='ffill').fillna(-1)
df_therm.to_csv(r'C:\Users\c00759961\Documents\temp\nina-MDA35B-camera-UHD-recording-after-thermal-timeline.csv')