-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR/REGR: Fix pandas.util.testing deprecation #30745
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 1 commit
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,60 @@ | ||
from pandas.util._decorators import Appender, Substitution, cache_readonly # noqa | ||
import importlib as _importlib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. umm why don't you actually just leave pandas.util.testing as a module itself? (and just re-import what you need). This is how we did all of the original deprecations. |
||
from importlib.abc import Loader as _Loader, MetaPathFinder | ||
from importlib.machinery import ModuleSpec as _ModuleSpec | ||
import sys as _sys | ||
import warnings as _warnings | ||
|
||
from pandas.core.util.hashing import hash_array, hash_pandas_object # noqa | ||
from pandas.util.testing import testing # noqa: F401 | ||
from pandas.util._decorators import Appender, Substitution, cache_readonly | ||
|
||
from pandas.core.util.hashing import hash_array, hash_pandas_object | ||
|
||
# Custom import hook for the deprecated pandas.util.testing module. | ||
# The custom Finder only runs when python's standard import fail, | ||
# since we're adding to the end of sys.meta_path. In TestingLoader.create_module | ||
# we simply warn and then return the real testing module, pandas._testing. | ||
# This differs from _DeprecatedModule by using the import system, which | ||
# allows it to work with both `import foo; foo.bar` and `from foo import bar`. | ||
# But because Python caches imports, the warning appears only once. | ||
|
||
|
||
class _TestingFinder(MetaPathFinder): | ||
@classmethod | ||
def find_spec(cls, fullname, path=None, target=None): | ||
|
||
name_parts = fullname.split(".") | ||
if name_parts[:3] != ["pandas", "util", "testing"] or len(name_parts) > 3: | ||
return None | ||
else: | ||
# return ModuleSpec(fullname, DataPackageImporter()) | ||
return _ModuleSpec(fullname, _TestingLoader()) | ||
|
||
|
||
class _TestingLoader(_Loader): | ||
@classmethod | ||
def create_module(cls, spec): | ||
module = _importlib.import_module("pandas._testing") | ||
_warnings.warn( | ||
( | ||
"pandas.util.testing is deprecated. Use the " | ||
"public methods from pandas.testing instead." | ||
), | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
return module | ||
|
||
@classmethod | ||
def exec_module(cls, module): | ||
pass | ||
|
||
|
||
_sys.meta_path.append(_TestingFinder()) | ||
|
||
|
||
__all__ = [ | ||
"Appender", | ||
"Substitution", | ||
"cache_readonly", | ||
"hash_array", | ||
"hash_pandas_object", | ||
] |
This file was deleted.
Oops, something went wrong.
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.
in theory this should be in a context manager (but nbd)