mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Python] Show call site in deprecation warnings
For warnings from pure Python methods, we need the 'stacklevel=2' argument to show the call in the users' code. For Cythonized methods, the default 'stacklevel=1' gives the desired result because the Cython method is not visible as part of the Python stacktrace.
This commit is contained in:
parent
493a63d44e
commit
8b7e4f24bf
@ -1203,7 +1203,7 @@ class SolutionArray(SolutionArrayBase):
|
|||||||
`write_csv` does not support escaping of commas within string entries.
|
`write_csv` does not support escaping of commas within string entries.
|
||||||
"""
|
"""
|
||||||
warnings.warn("SolutionArray.write_csv: Superseded by 'save' and will be removed "
|
warnings.warn("SolutionArray.write_csv: Superseded by 'save' and will be removed "
|
||||||
"after Cantera 3.0.", DeprecationWarning)
|
"after Cantera 3.0.", DeprecationWarning, stacklevel=2)
|
||||||
data_dict = self.collect_data(*args, cols=cols, tabular=True, **kwargs)
|
data_dict = self.collect_data(*args, cols=cols, tabular=True, **kwargs)
|
||||||
data = np.hstack([d[:, np.newaxis] for d in data_dict.values()])
|
data = np.hstack([d[:, np.newaxis] for d in data_dict.values()])
|
||||||
labels = list(data_dict.keys())
|
labels = list(data_dict.keys())
|
||||||
@ -1433,7 +1433,7 @@ class SolutionArray(SolutionArrayBase):
|
|||||||
warnings.warn("SolutionArray.write_hdf: To be removed after Cantera 3.0; use "
|
warnings.warn("SolutionArray.write_hdf: To be removed after Cantera 3.0; use "
|
||||||
"'save' instead.\n Note that the call is redirected to 'save' in order to "
|
"'save' instead.\n Note that the call is redirected to 'save' in order to "
|
||||||
"prevent the creation of a file with legacy HDF format;\nas a consequence, "
|
"prevent the creation of a file with legacy HDF format;\nas a consequence, "
|
||||||
"some options are no longer supported.", DeprecationWarning)
|
"some options are no longer supported.", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
if group is None:
|
if group is None:
|
||||||
raise KeyError("Missing required parameter 'group'.")
|
raise KeyError("Missing required parameter 'group'.")
|
||||||
@ -1477,7 +1477,7 @@ class SolutionArray(SolutionArrayBase):
|
|||||||
_import_h5py()
|
_import_h5py()
|
||||||
|
|
||||||
warnings.warn("SolutionArray.read_hdf: Method to be removed after Cantera 3.0; "
|
warnings.warn("SolutionArray.read_hdf: Method to be removed after Cantera 3.0; "
|
||||||
"use 'restore' instead.", DeprecationWarning)
|
"use 'restore' instead.", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
with _h5py.File(filename, 'r') as hdf:
|
with _h5py.File(filename, 'r') as hdf:
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class FlameBase(Sim1D):
|
|||||||
export to the C++ core, this method is unused.
|
export to the C++ core, this method is unused.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.other_components: Method to be removed after "
|
warnings.warn("FlameBase.other_components: Method to be removed after "
|
||||||
"Cantera 3.0 (unused).", DeprecationWarning)
|
"Cantera 3.0 (unused).", DeprecationWarning, stacklevel=2)
|
||||||
if domain is None:
|
if domain is None:
|
||||||
return self._other
|
return self._other
|
||||||
|
|
||||||
@ -385,7 +385,8 @@ class FlameBase(Sim1D):
|
|||||||
Replaceable by `profile` or `value`.
|
Replaceable by `profile` or `value`.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.solution: To be removed after Cantera 3.0. "
|
warnings.warn("FlameBase.solution: To be removed after Cantera 3.0. "
|
||||||
"Replaceable by 'profile' or 'value'.", DeprecationWarning)
|
"Replaceable by 'profile' or 'value'.", DeprecationWarning,
|
||||||
|
stacklevel=2)
|
||||||
if point is None:
|
if point is None:
|
||||||
return self.profile(self.flame, component)
|
return self.profile(self.flame, component)
|
||||||
else:
|
else:
|
||||||
@ -422,7 +423,7 @@ class FlameBase(Sim1D):
|
|||||||
Method to be removed after Cantera 3.0; superseded by `save`.
|
Method to be removed after Cantera 3.0; superseded by `save`.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.write_csv: Superseded by 'save'. To be removed "
|
warnings.warn("FlameBase.write_csv: Superseded by 'save'. To be removed "
|
||||||
"after Cantera 3.0.", DeprecationWarning)
|
"after Cantera 3.0.", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
# save data
|
# save data
|
||||||
cols = ('extra', 'T', 'D', species)
|
cols = ('extra', 'T', 'D', species)
|
||||||
@ -466,7 +467,7 @@ class FlameBase(Sim1D):
|
|||||||
Method to be removed after Cantera 3.0; superseded by `to_array`.
|
Method to be removed after Cantera 3.0; superseded by `to_array`.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.to_solution_array: To be removed after Cantera 3.0. "
|
warnings.warn("FlameBase.to_solution_array: To be removed after Cantera 3.0. "
|
||||||
"Replaceable by 'to_array'.", DeprecationWarning)
|
"Replaceable by 'to_array'.", DeprecationWarning, stacklevel=2)
|
||||||
return self.to_array(domain, normalize)
|
return self.to_array(domain, normalize)
|
||||||
|
|
||||||
def from_array(self, arr, domain=None):
|
def from_array(self, arr, domain=None):
|
||||||
@ -497,7 +498,7 @@ class FlameBase(Sim1D):
|
|||||||
Method to be removed after Cantera 3.0; replaced by `from_array`.
|
Method to be removed after Cantera 3.0; replaced by `from_array`.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.from_solution_array: To be removed after Cantera 3.0. "
|
warnings.warn("FlameBase.from_solution_array: To be removed after Cantera 3.0. "
|
||||||
"Replaced by 'from_array'.", DeprecationWarning)
|
"Replaced by 'from_array'.", DeprecationWarning, stacklevel=2)
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = self.flame
|
domain = self.flame
|
||||||
else:
|
else:
|
||||||
@ -636,7 +637,7 @@ class FlameBase(Sim1D):
|
|||||||
warnings.warn("FlameBase.write_hdf: To be removed after Cantera 3.0; use "
|
warnings.warn("FlameBase.write_hdf: To be removed after Cantera 3.0; use "
|
||||||
"'save' instead.\nNote that the call is redirected to 'save' in order to "
|
"'save' instead.\nNote that the call is redirected to 'save' in order to "
|
||||||
"prevent the creation of a file with deprecated HDF format.",
|
"prevent the creation of a file with deprecated HDF format.",
|
||||||
DeprecationWarning)
|
DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
self.save(filename, name=group, description=description,
|
self.save(filename, name=group, description=description,
|
||||||
compression=compression_opts)
|
compression=compression_opts)
|
||||||
@ -665,7 +666,7 @@ class FlameBase(Sim1D):
|
|||||||
Method to be removed after Cantera 3.0; superseded by `restore`.
|
Method to be removed after Cantera 3.0; superseded by `restore`.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.read_hdf: To be removed after Cantera 3.0; use "
|
warnings.warn("FlameBase.read_hdf: To be removed after Cantera 3.0; use "
|
||||||
"'restore' instead.", DeprecationWarning)
|
"'restore' instead.", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
if restore_boundaries:
|
if restore_boundaries:
|
||||||
domains = range(3)
|
domains = range(3)
|
||||||
@ -693,7 +694,7 @@ class FlameBase(Sim1D):
|
|||||||
`Domain1D.settings`; for the setter, use setters for individual settings.
|
`Domain1D.settings`; for the setter, use setters for individual settings.
|
||||||
"""
|
"""
|
||||||
warnings.warn("FlameBase.settings: to be removed after Cantera 3.0. Access "
|
warnings.warn("FlameBase.settings: to be removed after Cantera 3.0. Access "
|
||||||
"settings from domains instead.", DeprecationWarning)
|
"settings from domains instead.", DeprecationWarning, stacklevel=2)
|
||||||
out = {'Sim1D_type': type(self).__name__}
|
out = {'Sim1D_type': type(self).__name__}
|
||||||
out['transport_model'] = self.transport_model
|
out['transport_model'] = self.transport_model
|
||||||
out['energy_enabled'] = self.energy_enabled
|
out['energy_enabled'] = self.energy_enabled
|
||||||
@ -709,7 +710,7 @@ class FlameBase(Sim1D):
|
|||||||
@settings.setter
|
@settings.setter
|
||||||
def settings(self, s):
|
def settings(self, s):
|
||||||
warnings.warn("FlameBase.settings: To be removed after Cantera 3.0. Use "
|
warnings.warn("FlameBase.settings: To be removed after Cantera 3.0. Use "
|
||||||
"individual setters instead.", DeprecationWarning)
|
"individual setters instead.", DeprecationWarning, stacklevel=2)
|
||||||
# simple setters
|
# simple setters
|
||||||
attr = {'transport_model',
|
attr = {'transport_model',
|
||||||
'energy_enabled', 'soret_enabled', 'radiation_enabled',
|
'energy_enabled', 'soret_enabled', 'radiation_enabled',
|
||||||
@ -1045,7 +1046,7 @@ class IonFreeFlame(FreeFlame):
|
|||||||
def __init__(self, gas, grid=None, width=None):
|
def __init__(self, gas, grid=None, width=None):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"'IonFreeFlame' is deprecated and will be removed after Cantera 3.0;",
|
"'IonFreeFlame' is deprecated and will be removed after Cantera 3.0;",
|
||||||
"replaceable by 'FreeFlame'.", DeprecationWarning)
|
"replaceable by 'FreeFlame'.", DeprecationWarning, stacklevel=2)
|
||||||
super().__init__(gas, grid, width)
|
super().__init__(gas, grid, width)
|
||||||
|
|
||||||
|
|
||||||
@ -1199,7 +1200,7 @@ class IonBurnerFlame(BurnerFlame):
|
|||||||
def __init__(self, gas, grid=None, width=None):
|
def __init__(self, gas, grid=None, width=None):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
"'IonBurnerFlame' is deprecated and will be removed after Cantera 3.0; ",
|
"'IonBurnerFlame' is deprecated and will be removed after Cantera 3.0; ",
|
||||||
"replaceable by 'BurnerFlame'.", DeprecationWarning)
|
"replaceable by 'BurnerFlame'.", DeprecationWarning, stacklevel=2)
|
||||||
super().__init__(gas, grid, width)
|
super().__init__(gas, grid, width)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user