-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Validate dir
for pd.errors
and pd.util
#57140
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
73d7b1c
Ensure pandas.errors only imports its __all__
mroeschke 3ade455
Make public util API accessible
mroeschke 07cea82
Merge remote-tracking branch 'upstream/main' into api/stricter
mroeschke 4d83c8d
Fix import
mroeschke 8b4f466
Type input
mroeschke ffd77bf
Merge remote-tracking branch 'upstream/main' into api/stricter
mroeschke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
_chained_assignment_msg = ( | ||
"A value is trying to be set on a copy of a DataFrame or Series " | ||
"through chained assignment.\n" | ||
"When using the Copy-on-Write mode, such chained assignment never works " | ||
"to update the original DataFrame or Series, because the intermediate " | ||
"object on which we are setting values always behaves as a copy.\n\n" | ||
"Try using '.loc[row_indexer, col_indexer] = value' instead, to perform " | ||
"the assignment in a single step.\n\n" | ||
"See the caveats in the documentation: " | ||
"https://pandas.pydata.org/pandas-docs/stable/user_guide/" | ||
"indexing.html#returning-a-view-versus-a-copy" | ||
) | ||
|
||
|
||
_chained_assignment_method_msg = ( | ||
"A value is trying to be set on a copy of a DataFrame or Series " | ||
"through chained assignment using an inplace method.\n" | ||
"When using the Copy-on-Write mode, such inplace method never works " | ||
"to update the original DataFrame or Series, because the intermediate " | ||
"object on which we are setting values always behaves as a copy.\n\n" | ||
"For example, when doing 'df[col].method(value, inplace=True)', try " | ||
"using 'df.method({col: value}, inplace=True)' instead, to perform " | ||
"the operation inplace on the original object.\n\n" | ||
) | ||
|
||
|
||
_chained_assignment_warning_msg = ( | ||
"ChainedAssignmentError: behaviour will change in pandas 3.0!\n" | ||
"You are setting values through chained assignment. Currently this works " | ||
"in certain cases, but when using Copy-on-Write (which will become the " | ||
"default behaviour in pandas 3.0) this will never work to update the " | ||
"original DataFrame or Series, because the intermediate object on which " | ||
"we are setting values will behave as a copy.\n" | ||
"A typical example is when you are setting values in a column of a " | ||
"DataFrame, like:\n\n" | ||
'df["col"][row_indexer] = value\n\n' | ||
'Use `df.loc[row_indexer, "col"] = values` instead, to perform the ' | ||
"assignment in a single step and ensure this keeps updating the original `df`.\n\n" | ||
"See the caveats in the documentation: " | ||
"https://pandas.pydata.org/pandas-docs/stable/user_guide/" | ||
"indexing.html#returning-a-view-versus-a-copy\n" | ||
) | ||
|
||
_chained_assignment_warning_method_msg = ( | ||
"A value is trying to be set on a copy of a DataFrame or Series " | ||
"through chained assignment using an inplace method.\n" | ||
"The behavior will change in pandas 3.0. This inplace method will " | ||
"never work because the intermediate object on which we are setting " | ||
"values always behaves as a copy.\n\n" | ||
"For example, when doing 'df[col].method(value, inplace=True)', try " | ||
"using 'df.method({col: value}, inplace=True)' or " | ||
"df[col] = df[col].method(value) instead, to perform " | ||
"the operation inplace on the original object.\n\n" | ||
) | ||
|
||
|
||
def _check_cacher(obj) -> bool: | ||
# This is a mess, selection paths that return a view set the _cacher attribute | ||
# on the Series; most of them also set _item_cache which adds 1 to our relevant | ||
# reference count, but iloc does not, so we have to check if we are actually | ||
# in the item cache | ||
if hasattr(obj, "_cacher"): | ||
parent = obj._cacher[1]() | ||
# parent could be dead | ||
if parent is None: | ||
return False | ||
if hasattr(parent, "_item_cache"): | ||
if obj._cacher[0] in parent._item_cache: | ||
# Check if we are actually the item from item_cache, iloc creates a | ||
# new object | ||
return obj is parent._item_cache[obj._cacher[0]] | ||
return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've probably just missed this conversation along the way but what prevents us from prefixing these from an underscore to more clearly dictate that intent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Especially for
pandas.core
, I think there's an unknown amount of use of internals and I think a conservative approach is desired (i.e. formally deprecate) to wean users off of it #27522. Most pertinent in my mind is objects that can be returned that are not exposed in the public API #55905