本文整理匯總了Python中tables.NaturalNameWarning方法的典型用法代碼示例。如果您正苦於以下問題:Python tables.NaturalNameWarning方法的具體用法?Python tables.NaturalNameWarning怎麽用?Python tables.NaturalNameWarning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tables
的用法示例。
在下文中一共展示了tables.NaturalNameWarning方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_contains
# 需要導入模塊: import tables [as 別名]
# 或者: from tables import NaturalNameWarning [as 別名]
def test_contains(self):
with ensure_clean_store(self.path) as store:
store['a'] = tm.makeTimeSeries()
store['b'] = tm.makeDataFrame()
store['foo/bar'] = tm.makeDataFrame()
self.assert_('a' in store)
self.assert_('b' in store)
self.assert_('c' not in store)
self.assert_('foo/bar' in store)
self.assert_('/foo/bar' in store)
self.assert_('/foo/b' not in store)
self.assert_('bar' not in store)
# GH 2694
warnings.filterwarnings('ignore', category=tables.NaturalNameWarning)
store['node())'] = tm.makeDataFrame()
self.assert_('node())' in store)
示例2: write_to_hdf5
# 需要導入模塊: import tables [as 別名]
# 或者: from tables import NaturalNameWarning [as 別名]
def write_to_hdf5(metadata, h5file):
"""
Write metadata fields to a PyTables HDF5 file handle.
Parameters
----------
metadata: dict
flat dict as generated by `Reference.to_dict()`
h5file: tables.file.File
pytables filehandle
"""
from tables import NaturalNameWarning
with warnings.catch_warnings():
warnings.simplefilter("ignore", NaturalNameWarning)
for key, value in metadata.items():
h5file.root._v_attrs[key] = value # pylint: disable=protected-access
示例3: save
# 需要導入模塊: import tables [as 別名]
# 或者: from tables import NaturalNameWarning [as 別名]
def save(prob, filename):
"""Save urbs model input and result cache to a HDF5 store file.
Args:
- prob: a urbs model instance containing a solution
- filename: HDF5 store file to be written
Returns:
Nothing
"""
import warnings
import tables
warnings.filterwarnings('ignore',
category=pd.io.pytables.PerformanceWarning)
warnings.filterwarnings('ignore',
category=tables.NaturalNameWarning)
if not hasattr(prob, '_result'):
prob._result = create_result_cache(prob)
with pd.HDFStore(filename, mode='w') as store:
for name in prob._data.keys():
store['data/'+name] = prob._data[name]
for name in prob._result.keys():
store['result/'+name] = prob._result[name]
示例4: test_parameters
# 需要導入模塊: import tables [as 別名]
# 或者: from tables import NaturalNameWarning [as 別名]
def test_parameters(self, simple_linear_model, tmpdir):
"""
Test the TablesRecorder
"""
from pywr.parameters import ConstantParameter
model = simple_linear_model
otpt = model.nodes['Output']
inpt = model.nodes['Input']
p = ConstantParameter(model, 10.0, name='max_flow')
inpt.max_flow = p
# ensure TablesRecorder can handle parameters with a / in the name
p_slash = ConstantParameter(model, 0.0, name='name with a / in it')
inpt.min_flow = p_slash
agg_node = AggregatedNode(model, 'Sum', [otpt, inpt])
inpt.max_flow = 10.0
otpt.cost = -2.0
h5file = tmpdir.join('output.h5')
import tables
with tables.open_file(str(h5file), 'w') as h5f:
with pytest.warns(ParameterNameWarning):
rec = TablesRecorder(model, h5f, parameters=[p, p_slash])
# check parameters have been added to the component tree
# this is particularly important for parameters which update their
# values in `after`, e.g. DeficitParameter (see #465)
assert(not model.find_orphaned_parameters())
assert(p in rec.children)
assert(p_slash in rec.children)
with pytest.warns(tables.NaturalNameWarning):
model.run()
for node_name in model.nodes.keys():
ca = h5f.get_node('/', node_name)
assert ca.shape == (365, 1)
if node_name == 'Sum':
np.testing.assert_allclose(ca, 20.0)
elif "name with a" in node_name:
assert(node_name == "name with a _ in it")
np.testing.assert_allclose(ca, 0.0)
else:
np.testing.assert_allclose(ca, 10.0)