-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH] Stacklevel offset #68
Comments
ANALYSISThe issue with the current code is that the warning message is not being displayed due to the deprecation warning being triggered from the To understand the current warning filter settings, you can display them using the following code: import warnings
import pprint
pprint.pprint(warnings.filters, width=200) This will provide the output: [('default', None, <class 'DeprecationWarning'>, '__main__', 0),
('ignore', None, <class 'DeprecationWarning' >, None, 0),
('ignore', None, <class 'PendingDeprecationWarning' >, None, 0),
('ignore', None, <class 'ImportWarning' >, None, 0),
('ignore', None, <class 'ResourceWarning' >, None, 0)] To address the issue in your demo script, you can add a filter: import warnings
import pandas as pd
from deprecated import deprecated
@pd.api.extensions.register_dataframe_accessor("idx")
@deprecated()
class IdxAccessor:
def __init__(self, pandas_obj):
self._obj = pandas_obj
# Always trigger deprecation warnings
warnings.filterwarnings("default", category=DeprecationWarning)
df = pd.DataFrame()
_ = df.idx This will result in the following warning message: /path/to/venv/lib/python3.8/site-packages/pandas/core/accessor.py:224: DeprecationWarning: Call to deprecated class IdxAccessor.
accessor_obj = self._accessor(obj) If I understand your issue correctly, you want to have a warning message when the user accesses the Here, With the current implementation of the This implies two things:
|
ProposalRegarding the issue you encountered, it can be considered as a bug. To address this, I suggest preparing a fix based on the By incorporating the With this modification, users can pass an Please let me know if you need any further assistance or clarification. Good luck with the fix! |
Acceptance Criteria
|
Very good job! Congratulations 🎉 Jonas! |
Deprecate idx in favour of pix. Deprecation warning is not yet triggered automatically due to laurent-laporte-pro/deprecated#68 .
Over at coroa/pandas-indexing#27, I am about to deprecate a pandas accessor, but since these accessors are classes, which are instantiated by pandas upon access the warning is not emitted since the
stacklevel
is too low.MWE
will only emit with a
warnings.simplefilter("always")
warnings.simplefilter("default")
(edit: changed to include "default" which was pointed out below), since the callstack looks like:so that the last
stacklevel=2
setting points to thepandas.core.accessor
module instead of the user code.Proposal
Would you accept a PR to add a
stacklevel_offset
orstacklevel
argument to deprecated which would either be added like:or could be used to replace the default
stacklevel
, like:The text was updated successfully, but these errors were encountered: