|
67 | 67 | doc,
|
68 | 68 | rewrite_axis_style_signature,
|
69 | 69 | )
|
| 70 | +from pandas.util._exceptions import find_stack_level |
70 | 71 | from pandas.util._validators import (
|
71 | 72 | validate_ascending,
|
72 | 73 | validate_bool_kwarg,
|
@@ -3506,7 +3507,7 @@ def _maybe_update_cacher(
|
3506 | 3507 | """
|
3507 | 3508 |
|
3508 | 3509 | if verify_is_copy:
|
3509 |
| - self._check_setitem_copy(stacklevel=5, t="referent") |
| 3510 | + self._check_setitem_copy(t="referent") |
3510 | 3511 |
|
3511 | 3512 | if clear:
|
3512 | 3513 | self._clear_item_cache()
|
@@ -3853,26 +3854,21 @@ def _check_is_chained_assignment_possible(self) -> bool_t:
|
3853 | 3854 | setting.
|
3854 | 3855 | """
|
3855 | 3856 | if self._is_copy:
|
3856 |
| - self._check_setitem_copy(stacklevel=4, t="referent") |
| 3857 | + self._check_setitem_copy(t="referent") |
3857 | 3858 | return False
|
3858 | 3859 |
|
3859 | 3860 | @final
|
3860 |
| - def _check_setitem_copy(self, stacklevel=4, t="setting", force=False): |
| 3861 | + def _check_setitem_copy(self, t="setting", force=False): |
3861 | 3862 | """
|
3862 | 3863 |
|
3863 | 3864 | Parameters
|
3864 | 3865 | ----------
|
3865 |
| - stacklevel : int, default 4 |
3866 |
| - the level to show of the stack when the error is output |
3867 | 3866 | t : str, the type of setting error
|
3868 | 3867 | force : bool, default False
|
3869 | 3868 | If True, then force showing an error.
|
3870 | 3869 |
|
3871 | 3870 | validate if we are doing a setitem on a chained copy.
|
3872 | 3871 |
|
3873 |
| - If you call this function, be sure to set the stacklevel such that the |
3874 |
| - user will see the error *at the level of setting* |
3875 |
| -
|
3876 | 3872 | It is technically possible to figure out that we are setting on
|
3877 | 3873 | a copy even WITH a multi-dtyped pandas object. In other words, some
|
3878 | 3874 | blocks may be views while other are not. Currently _is_view will ALWAYS
|
@@ -3931,7 +3927,7 @@ def _check_setitem_copy(self, stacklevel=4, t="setting", force=False):
|
3931 | 3927 | if value == "raise":
|
3932 | 3928 | raise com.SettingWithCopyError(t)
|
3933 | 3929 | elif value == "warn":
|
3934 |
| - warnings.warn(t, com.SettingWithCopyWarning, stacklevel=stacklevel) |
| 3930 | + warnings.warn(t, com.SettingWithCopyWarning, stacklevel=find_stack_level()) |
3935 | 3931 |
|
3936 | 3932 | def __delitem__(self, key) -> None:
|
3937 | 3933 | """
|
|
0 commit comments