本文整理汇总了Python中pandas.util.testing.makeTimeSeries方法的典型用法代码示例。如果您正苦于以下问题:Python testing.makeTimeSeries方法的具体用法?Python testing.makeTimeSeries怎么用?Python testing.makeTimeSeries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.makeTimeSeries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_concat_series
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_concat_series(self):
ts = tm.makeTimeSeries()
ts.name = 'foo'
pieces = [ts[:5], ts[5:15], ts[15:]]
result = concat(pieces)
tm.assert_series_equal(result, ts)
assert result.name == ts.name
result = concat(pieces, keys=[0, 1, 2])
expected = ts.copy()
ts.index = DatetimeIndex(np.array(ts.index.values, dtype='M8[ns]'))
exp_codes = [np.repeat([0, 1, 2], [len(x) for x in pieces]),
np.arange(len(ts))]
exp_index = MultiIndex(levels=[[0, 1, 2], ts.index],
codes=exp_codes)
expected.index = exp_index
tm.assert_series_equal(result, expected)
示例2: test_gap_upsample
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_gap_upsample(self):
low = tm.makeTimeSeries()
low[5:25] = np.nan
_, ax = self.plt.subplots()
low.plot(ax=ax)
idxh = date_range(low.index[0], low.index[-1], freq='12h')
s = Series(np.random.randn(len(idxh)), idxh)
s.plot(secondary_y=True)
lines = ax.get_lines()
assert len(lines) == 1
assert len(ax.right_ax.get_lines()) == 1
line = lines[0]
data = line.get_xydata()
if (self.mpl_ge_3_0_0 or not self.mpl_ge_2_0_1
or (self.mpl_ge_2_1_0 and not self.mpl_ge_2_2_2)):
# 2.0.0, 2.2.0 (exactly) or >= 3.0.0
data = np.ma.MaskedArray(data, mask=isna(data), fill_value=np.nan)
assert isinstance(data, np.ma.core.MaskedArray)
mask = data.mask
assert mask[5:25, 1].all()
示例3: test_mixed_freq_regular_first_df
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_mixed_freq_regular_first_df(self):
# GH 9852
s1 = tm.makeTimeSeries().to_frame()
s2 = s1.iloc[[0, 5, 10, 11, 12, 13, 14, 15], :]
_, ax = self.plt.subplots()
s1.plot(ax=ax)
ax2 = s2.plot(style='g', ax=ax)
lines = ax2.get_lines()
idx1 = PeriodIndex(lines[0].get_xdata())
idx2 = PeriodIndex(lines[1].get_xdata())
assert idx1.equals(s1.index.to_period('B'))
assert idx2.equals(s2.index.to_period('B'))
left, right = ax2.get_xlim()
pidx = s1.index.to_period()
assert left <= pidx[0].ordinal
assert right >= pidx[-1].ordinal
示例4: test_operators_frame
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_operators_frame(self):
# rpow does not work with DataFrame
ts = tm.makeTimeSeries()
ts.name = 'ts'
df = pd.DataFrame({'A': ts})
tm.assert_series_equal(ts + ts, ts + df['A'],
check_names=False)
tm.assert_series_equal(ts ** ts, ts ** df['A'],
check_names=False)
tm.assert_series_equal(ts < ts, ts < df['A'],
check_names=False)
tm.assert_series_equal(ts / ts, ts / df['A'],
check_names=False)
# TODO: this came from tests.series.test_analytics, needs cleannup and
# de-duplication with test_modulo above
示例5: test_var_std
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_var_std(self):
string_series = tm.makeStringSeries().rename('series')
datetime_series = tm.makeTimeSeries().rename('ts')
alt = lambda x: np.std(x, ddof=1)
self._check_stat_op('std', alt, string_series)
alt = lambda x: np.var(x, ddof=1)
self._check_stat_op('var', alt, string_series)
result = datetime_series.std(ddof=4)
expected = np.std(datetime_series.values, ddof=4)
tm.assert_almost_equal(result, expected)
result = datetime_series.var(ddof=4)
expected = np.var(datetime_series.values, ddof=4)
tm.assert_almost_equal(result, expected)
# 1 - element series with ddof=1
s = datetime_series.iloc[[0]]
result = s.var(ddof=1)
assert pd.isna(result)
result = s.std(ddof=1)
assert pd.isna(result)
示例6: test_sem
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_sem(self):
string_series = tm.makeStringSeries().rename('series')
datetime_series = tm.makeTimeSeries().rename('ts')
alt = lambda x: np.std(x, ddof=1) / np.sqrt(len(x))
self._check_stat_op('sem', alt, string_series)
result = datetime_series.sem(ddof=4)
expected = np.std(datetime_series.values,
ddof=4) / np.sqrt(len(datetime_series.values))
tm.assert_almost_equal(result, expected)
# 1 - element series with ddof=1
s = datetime_series.iloc[[0]]
result = s.sem(ddof=1)
assert pd.isna(result)
示例7: test_concat_series
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_concat_series(self):
ts = tm.makeTimeSeries()
ts.name = 'foo'
pieces = [ts[:5], ts[5:15], ts[15:]]
result = concat(pieces)
tm.assert_series_equal(result, ts)
assert result.name == ts.name
result = concat(pieces, keys=[0, 1, 2])
expected = ts.copy()
ts.index = DatetimeIndex(np.array(ts.index.values, dtype='M8[ns]'))
exp_labels = [np.repeat([0, 1, 2], [len(x) for x in pieces]),
np.arange(len(ts))]
exp_index = MultiIndex(levels=[[0, 1, 2], ts.index],
labels=exp_labels)
expected.index = exp_index
tm.assert_series_equal(result, expected)
示例8: test_mixed_freq_regular_first
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_mixed_freq_regular_first(self):
# TODO
s1 = tm.makeTimeSeries()
s2 = s1[[0, 5, 10, 11, 12, 13, 14, 15]]
# it works!
_, ax = self.plt.subplots()
s1.plot(ax=ax)
ax2 = s2.plot(style='g', ax=ax)
lines = ax2.get_lines()
idx1 = PeriodIndex(lines[0].get_xdata())
idx2 = PeriodIndex(lines[1].get_xdata())
tm.assert_index_equal(idx1, s1.index.to_period('B'))
tm.assert_index_equal(idx2, s2.index.to_period('B'))
left, right = ax2.get_xlim()
pidx = s1.index.to_period()
assert left <= pidx[0].ordinal
assert right >= pidx[-1].ordinal
示例9: test_rolling_corr
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_rolling_corr(self):
A = self.series
B = A + randn(len(A))
result = A.rolling(window=50, min_periods=25).corr(B)
tm.assert_almost_equal(result[-1], np.corrcoef(A[-50:], B[-50:])[0, 1])
# test for correct bias correction
a = tm.makeTimeSeries()
b = tm.makeTimeSeries()
a[:5] = np.nan
b[:10] = np.nan
result = a.rolling(window=len(a), min_periods=1).corr(b)
tm.assert_almost_equal(result[-1], a.corr(b))
示例10: test_concat_series_axis1
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_concat_series_axis1(self, sort=sort):
ts = tm.makeTimeSeries()
pieces = [ts[:-2], ts[2:], ts[2:-2]]
result = concat(pieces, axis=1)
expected = DataFrame(pieces).T
assert_frame_equal(result, expected)
result = concat(pieces, keys=['A', 'B', 'C'], axis=1)
expected = DataFrame(pieces, index=['A', 'B', 'C']).T
assert_frame_equal(result, expected)
# preserve series names, #2489
s = Series(randn(5), name='A')
s2 = Series(randn(5), name='B')
result = concat([s, s2], axis=1)
expected = DataFrame({'A': s, 'B': s2})
assert_frame_equal(result, expected)
s2.name = None
result = concat([s, s2], axis=1)
tm.assert_index_equal(result.columns,
Index(['A', 0], dtype='object'))
# must reindex, #2603
s = Series(randn(3), index=['c', 'a', 'b'], name='A')
s2 = Series(randn(4), index=['d', 'a', 'b', 'c'], name='B')
result = concat([s, s2], axis=1, sort=sort)
expected = DataFrame({'A': s, 'B': s2})
assert_frame_equal(result, expected)
示例11: test_concat_bug_1719
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_concat_bug_1719(self):
ts1 = tm.makeTimeSeries()
ts2 = tm.makeTimeSeries()[::2]
# to join with union
# these two are of different length!
left = concat([ts1, ts2], join='outer', axis=1)
right = concat([ts2, ts1], join='outer', axis=1)
assert len(left) == len(right)
示例12: setup_method
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def setup_method(self, method):
TestPlotBase.setup_method(self, method)
import matplotlib as mpl
mpl.rcdefaults()
self.ts = tm.makeTimeSeries()
self.ts.name = 'ts'
示例13: setup_method
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def setup_method(self, method):
TestPlotBase.setup_method(self, method)
import matplotlib as mpl
mpl.rcdefaults()
self.ts = tm.makeTimeSeries()
self.ts.name = 'ts'
self.series = tm.makeStringSeries()
self.series.name = 'series'
self.iseries = tm.makePeriodSeries()
self.iseries.name = 'iseries'
示例14: test_tsplot_deprecated
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_tsplot_deprecated(self):
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
with tm.assert_produces_warning(FutureWarning):
tsplot(ts, self.plt.Axes.plot, ax=ax)
示例15: test_tsplot
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeTimeSeries [as 别名]
def test_tsplot(self):
from pandas.tseries.plotting import tsplot
_, ax = self.plt.subplots()
ts = tm.makeTimeSeries()
def f(*args, **kwds):
with tm.assert_produces_warning(FutureWarning):
return tsplot(s, self.plt.Axes.plot, *args, **kwds)
for s in self.period_ser:
_check_plot_works(f, s.index.freq, ax=ax, series=s)
for s in self.datetime_ser:
_check_plot_works(f, s.index.freq.rule_code, ax=ax, series=s)
for s in self.period_ser:
_check_plot_works(s.plot, ax=ax)
for s in self.datetime_ser:
_check_plot_works(s.plot, ax=ax)
_, ax = self.plt.subplots()
ts.plot(style='k', ax=ax)
color = (0., 0., 0., 1)
assert color == ax.get_lines()[0].get_color()