本文整理汇总了Python中pandas.util.testing.makePanel方法的典型用法代码示例。如果您正苦于以下问题:Python testing.makePanel方法的具体用法?Python testing.makePanel怎么用?Python testing.makePanel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.makePanel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reshaping_panel_categorical
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_reshaping_panel_categorical(self):
p = tm.makePanel()
p['str'] = 'foo'
df = p.to_frame()
df['category'] = df['str'].astype('category')
result = df['category'].unstack()
c = Categorical(['foo'] * len(p.major_axis))
expected = DataFrame({'A': c.copy(),
'B': c.copy(),
'C': c.copy(),
'D': c.copy()},
columns=Index(list('ABCD'), name='minor'),
index=p.major_axis.set_names('major'))
tm.assert_frame_equal(result, expected)
示例2: test_to_xarray
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_to_xarray(self):
from xarray import DataArray
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()
result = p.to_xarray()
assert isinstance(result, DataArray)
assert len(result.coords) == 3
assert_almost_equal(list(result.coords.keys()),
['items', 'major_axis', 'minor_axis'])
assert len(result.dims) == 3
# idempotency
assert_panel_equal(result.to_pandas(), p)
# run all the tests, but wrap each in a warning catcher
示例3: test_transpose
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_transpose(self):
msg = (r"transpose\(\) got multiple values for "
r"keyword argument 'axes'")
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries()]:
# calls implementation in pandas/core/base.py
tm.assert_series_equal(s.transpose(), s)
for df in [tm.makeTimeDataFrame()]:
tm.assert_frame_equal(df.transpose().transpose(), df)
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
for p in [tm.makePanel()]:
tm.assert_panel_equal(p.transpose(2, 0, 1)
.transpose(1, 2, 0), p)
with pytest.raises(TypeError, match=msg):
p.transpose(2, 0, 1, axes=(2, 0, 1))
示例4: test_numpy_transpose
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_numpy_transpose(self):
msg = "the 'axes' parameter is not supported"
s = tm.makeFloatSeries()
tm.assert_series_equal(np.transpose(s), s)
with pytest.raises(ValueError, match=msg):
np.transpose(s, axes=1)
df = tm.makeTimeDataFrame()
tm.assert_frame_equal(np.transpose(np.transpose(df)), df)
with pytest.raises(ValueError, match=msg):
np.transpose(df, axes=1)
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()
tm.assert_panel_equal(np.transpose(
np.transpose(p, axes=(2, 0, 1)),
axes=(1, 2, 0)), p)
示例5: test_take_invalid_kwargs
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_take_invalid_kwargs(self):
indices = [-3, 2, 0, 1]
s = tm.makeFloatSeries()
df = tm.makeTimeDataFrame()
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
p = tm.makePanel()
for obj in (s, df, p):
msg = r"take\(\) got an unexpected keyword argument 'foo'"
with pytest.raises(TypeError, match=msg):
obj.take(indices, foo=2)
msg = "the 'out' parameter is not supported"
with pytest.raises(ValueError, match=msg):
obj.take(indices, out=indices)
msg = "the 'mode' parameter is not supported"
with pytest.raises(ValueError, match=msg):
obj.take(indices, mode='clip')
示例6: test_sparse_friendly
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_sparse_friendly(df):
sdf = df[['C', 'D']].to_sparse()
panel = tm.makePanel()
tm.add_nans(panel)
def _check_work(gp):
gp.mean()
gp.agg(np.mean)
dict(iter(gp))
# it works!
_check_work(sdf.groupby(lambda x: x // 2))
_check_work(sdf['C'].groupby(lambda x: x // 2))
_check_work(sdf.groupby(df['A']))
# do this someday
# _check_work(panel.groupby(lambda x: x.month, axis=1))
示例7: test_reshaping_panel_categorical
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_reshaping_panel_categorical(self):
with catch_warnings(record=True):
p = tm.makePanel()
p['str'] = 'foo'
df = p.to_frame()
df['category'] = df['str'].astype('category')
result = df['category'].unstack()
c = Categorical(['foo'] * len(p.major_axis))
expected = DataFrame({'A': c.copy(),
'B': c.copy(),
'C': c.copy(),
'D': c.copy()},
columns=Index(list('ABCD'), name='minor'),
index=p.major_axis.set_names('major'))
tm.assert_frame_equal(result, expected)
示例8: test_to_xarray
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_to_xarray(self):
from xarray import DataArray
with catch_warnings(record=True):
p = tm.makePanel()
result = p.to_xarray()
assert isinstance(result, DataArray)
assert len(result.coords) == 3
assert_almost_equal(list(result.coords.keys()),
['items', 'major_axis', 'minor_axis'])
assert len(result.dims) == 3
# idempotency
assert_panel_equal(result.to_pandas(), p)
# run all the tests, but wrap each in a warning catcher
示例9: test_transpose
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_transpose(self):
msg = (r"transpose\(\) got multiple values for "
r"keyword argument 'axes'")
for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
tm.makeObjectSeries()]:
# calls implementation in pandas/core/base.py
tm.assert_series_equal(s.transpose(), s)
for df in [tm.makeTimeDataFrame()]:
tm.assert_frame_equal(df.transpose().transpose(), df)
with catch_warnings(record=True):
for p in [tm.makePanel()]:
tm.assert_panel_equal(p.transpose(2, 0, 1)
.transpose(1, 2, 0), p)
tm.assert_raises_regex(TypeError, msg, p.transpose,
2, 0, 1, axes=(2, 0, 1))
示例10: test_numpy_transpose
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_numpy_transpose(self):
msg = "the 'axes' parameter is not supported"
s = tm.makeFloatSeries()
tm.assert_series_equal(
np.transpose(s), s)
tm.assert_raises_regex(ValueError, msg,
np.transpose, s, axes=1)
df = tm.makeTimeDataFrame()
tm.assert_frame_equal(np.transpose(
np.transpose(df)), df)
tm.assert_raises_regex(ValueError, msg,
np.transpose, df, axes=1)
with catch_warnings(record=True):
p = tm.makePanel()
tm.assert_panel_equal(np.transpose(
np.transpose(p, axes=(2, 0, 1)),
axes=(1, 2, 0)), p)
示例11: test_take_invalid_kwargs
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_take_invalid_kwargs(self):
indices = [-3, 2, 0, 1]
s = tm.makeFloatSeries()
df = tm.makeTimeDataFrame()
with catch_warnings(record=True):
p = tm.makePanel()
for obj in (s, df, p):
msg = r"take\(\) got an unexpected keyword argument 'foo'"
tm.assert_raises_regex(TypeError, msg, obj.take,
indices, foo=2)
msg = "the 'out' parameter is not supported"
tm.assert_raises_regex(ValueError, msg, obj.take,
indices, out=indices)
msg = "the 'mode' parameter is not supported"
tm.assert_raises_regex(ValueError, msg, obj.take,
indices, mode='clip')
示例12: test_sparse_friendly
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_sparse_friendly(df):
sdf = df[['C', 'D']].to_sparse()
with catch_warnings(record=True):
panel = tm.makePanel()
tm.add_nans(panel)
def _check_work(gp):
gp.mean()
gp.agg(np.mean)
dict(iter(gp))
# it works!
_check_work(sdf.groupby(lambda x: x // 2))
_check_work(sdf['C'].groupby(lambda x: x // 2))
_check_work(sdf.groupby(df['A']))
# do this someday
# _check_work(panel.groupby(lambda x: x.month, axis=1))
示例13: test_legacy_table_write
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_legacy_table_write(self):
raise nose.SkipTest("skipping for now")
store = HDFStore(tm.get_data_path('legacy_hdf/legacy_table_%s.h5' % pandas.__version__), 'a')
df = tm.makeDataFrame()
wp = tm.makePanel()
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
['one', 'two', 'three']],
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
names=['foo', 'bar'])
df = DataFrame(np.random.randn(10, 3), index=index,
columns=['A', 'B', 'C'])
store.append('mi', df)
df = DataFrame(dict(A = 'foo', B = 'bar'),index=lrange(10))
store.append('df', df, data_columns = ['B'], min_itemsize={'A' : 200 })
store.append('wp', wp)
store.close()
示例14: make_test_panel
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def make_test_panel():
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
_panel = tm.makePanel()
tm.add_nans(_panel)
_panel = _panel.copy()
return _panel
示例15: test_comparisons
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makePanel [as 别名]
def test_comparisons(self):
p1 = tm.makePanel()
p2 = tm.makePanel()
tp = p1.reindex(items=p1.items + ['foo'])
df = p1[p1.items[0]]
def test_comp(func):
# versus same index
result = func(p1, p2)
tm.assert_numpy_array_equal(result.values,
func(p1.values, p2.values))
# versus non-indexed same objs
pytest.raises(Exception, func, p1, tp)
# versus different objs
pytest.raises(Exception, func, p1, df)
# versus scalar
result3 = func(self.panel, 0)
tm.assert_numpy_array_equal(result3.values,
func(self.panel.values, 0))
with np.errstate(invalid='ignore'):
test_comp(operator.eq)
test_comp(operator.ne)
test_comp(operator.lt)
test_comp(operator.gt)
test_comp(operator.ge)
test_comp(operator.le)