本文整理汇总了Python中pandas.core.config.option_context方法的典型用法代码示例。如果您正苦于以下问题:Python config.option_context方法的具体用法?Python config.option_context怎么用?Python config.option_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.core.config
的用法示例。
在下文中一共展示了config.option_context方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sparse_mi_max_row
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_mi_max_row(self):
idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0),
('C', 0), ('C', 1), ('C', 2)])
s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan],
index=idx).to_sparse()
result = repr(s)
dfm = self.dtype_format_for_platform
exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n"
"C 0 3.0\n 1 NaN\n 2 NaN\n"
"dtype: Sparse[float64, nan]\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
with option_context("display.max_rows", 3,
"display.show_dimensions", False):
# GH 13144
result = repr(s)
exp = ("A 0 1.0\n ... \nC 2 NaN\n"
"dtype: Sparse[float64, nan]\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
示例2: test_sparse_bool
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_bool(self):
# GH 13110
s = pd.SparseSeries([True, False, False, True, False, False],
fill_value=False)
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
exp = ("0 True\n1 False\n2 False\n"
"3 True\n4 False\n5 False\n"
"dtype: Sparse[bool, False]\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
with option_context("display.max_rows", 3):
result = repr(s)
exp = ("0 True\n ... \n5 False\n"
"Length: 6, dtype: Sparse[bool, False]\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
示例3: test_sparse_int
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_int(self):
# GH 13110
s = pd.SparseSeries([0, 1, 0, 0, 1, 0], fill_value=False)
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
exp = ("0 0\n1 1\n2 0\n3 0\n4 1\n"
"5 0\ndtype: Sparse[int64, False]\nBlockIndex\n"
"Block locations: array([1, 4]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
with option_context("display.max_rows", 3,
"display.show_dimensions", False):
result = repr(s)
exp = ("0 0\n ..\n5 0\n"
"dtype: Sparse[int64, False]\nBlockIndex\n"
"Block locations: array([1, 4]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
示例4: test_option_no_warning
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_option_no_warning(self):
pytest.importorskip("matplotlib.pyplot")
ctx = cf.option_context("plotting.matplotlib.register_converters",
False)
plt = pytest.importorskip("matplotlib.pyplot")
s = Series(range(12), index=date_range('2017', periods=12))
_, ax = plt.subplots()
converter._WARN = True
# Test without registering first, no warning
with ctx:
with tm.assert_produces_warning(None) as w:
ax.plot(s.index, s.values)
assert len(w) == 0
# Now test with registering
converter._WARN = True
register_matplotlib_converters()
with ctx:
with tm.assert_produces_warning(None) as w:
ax.plot(s.index, s.values)
assert len(w) == 0
示例5: test_transform_mixed_type
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_transform_mixed_type():
index = MultiIndex.from_arrays([[0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3]
])
df = DataFrame({'d': [1., 1., 1., 2., 2., 2.],
'c': np.tile(['a', 'b', 'c'], 2),
'v': np.arange(1., 7.)}, index=index)
def f(group):
group['g'] = group['d'] * 2
return group[:1]
grouped = df.groupby('c')
result = grouped.apply(f)
assert result['d'].dtype == np.float64
# this is by definition a mutating operation!
with option_context('mode.chained_assignment', None):
for key, group in grouped:
res = f(group)
assert_frame_equal(res, result.loc[key])
示例6: test_publishes
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_publishes(self):
df = pd.DataFrame({"A": [1, 2]})
objects = [df['A'], df, df] # dataframe / series
expected_keys = [
{'text/plain', 'application/vnd.dataresource+json'},
{'text/plain', 'text/html', 'application/vnd.dataresource+json'},
]
opt = pd.option_context('display.html.table_schema', True)
for obj, expected in zip(objects, expected_keys):
with opt:
formatted = self.display_formatter.format(obj)
assert set(formatted[0].keys()) == expected
with_latex = pd.option_context('display.latex.repr', True)
with opt, with_latex:
formatted = self.display_formatter.format(obj)
expected = {'text/plain', 'text/html', 'text/latex',
'application/vnd.dataresource+json'}
assert set(formatted[0].keys()) == expected
示例7: test_enable_data_resource_formatter
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_enable_data_resource_formatter(self):
# GH 10491
formatters = self.display_formatter.formatters
mimetype = 'application/vnd.dataresource+json'
with pd.option_context('display.html.table_schema', True):
assert 'application/vnd.dataresource+json' in formatters
assert formatters[mimetype].enabled
# still there, just disabled
assert 'application/vnd.dataresource+json' in formatters
assert not formatters[mimetype].enabled
# able to re-set
with pd.option_context('display.html.table_schema', True):
assert 'application/vnd.dataresource+json' in formatters
assert formatters[mimetype].enabled
# smoke test that it works
self.display_formatter.format(cf)
示例8: test_sparse_max_row
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_max_row(self):
s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse()
result = repr(s)
dfm = self.dtype_format_for_platform
exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n"
"4 NaN\ndtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
with option_context("display.max_rows", 3):
# GH 10560
result = repr(s)
exp = ("0 1.0\n ... \n4 NaN\n"
"Length: 5, dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
示例9: test_sparse_mi_max_row
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_mi_max_row(self):
idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0),
('C', 0), ('C', 1), ('C', 2)])
s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan],
index=idx).to_sparse()
result = repr(s)
dfm = self.dtype_format_for_platform
exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n"
"C 0 3.0\n 1 NaN\n 2 NaN\n"
"dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
with option_context("display.max_rows", 3,
"display.show_dimensions", False):
# GH 13144
result = repr(s)
exp = ("A 0 1.0\n ... \nC 2 NaN\n"
"dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
assert result == exp
示例10: test_sparse_bool
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_bool(self):
# GH 13110
s = pd.SparseSeries([True, False, False, True, False, False],
fill_value=False)
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
exp = ("0 True\n1 False\n2 False\n"
"3 True\n4 False\n5 False\n"
"dtype: bool\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
with option_context("display.max_rows", 3):
result = repr(s)
exp = ("0 True\n ... \n5 False\n"
"Length: 6, dtype: bool\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
示例11: test_sparse_int
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_sparse_int(self):
# GH 13110
s = pd.SparseSeries([0, 1, 0, 0, 1, 0], fill_value=False)
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
exp = ("0 0\n1 1\n2 0\n3 0\n4 1\n"
"5 0\ndtype: int64\nBlockIndex\n"
"Block locations: array([1, 4]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
with option_context("display.max_rows", 3,
"display.show_dimensions", False):
result = repr(s)
exp = ("0 0\n ..\n5 0\n"
"dtype: int64\nBlockIndex\n"
"Block locations: array([1, 4]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
assert result == exp
示例12: apply
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def apply(self, func, *args, **kwargs):
func = self._is_builtin_func(func)
# this is needed so we don't try and wrap strings. If we could
# resolve functions to their callable functions prior, this
# wouldn't be needed
if args or kwargs:
if callable(func):
@wraps(func)
def f(g):
with np.errstate(all='ignore'):
return func(g, *args, **kwargs)
else:
raise ValueError('func must be a callable if args or '
'kwargs are supplied')
else:
f = func
# ignore SettingWithCopy here in case the user mutates
with option_context('mode.chained_assignment', None):
return self._python_apply_general(f)
示例13: test_transform_mixed_type
# 需要导入模块: from pandas.core import config [as 别名]
# 或者: from pandas.core.config import option_context [as 别名]
def test_transform_mixed_type(self):
index = MultiIndex.from_arrays([[0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3]
])
df = DataFrame({'d': [1., 1., 1., 2., 2., 2.],
'c': np.tile(['a', 'b', 'c'], 2),
'v': np.arange(1., 7.)}, index=index)
def f(group):
group['g'] = group['d'] * 2
return group[:1]
grouped = df.groupby('c')
result = grouped.apply(f)
assert result['d'].dtype == np.float64
# this is by definition a mutating operation!
with option_context('mode.chained_assignment', None):
for key, group in grouped:
res = f(group)
assert_frame_equal(res, result.loc[key])