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] performance optimization for _check_soft_dependencies
, speed up test collection time
#6355
base: main
Are you sure you want to change the base?
Conversation
@benHeid, @yarnabrina, I have no reasonable explanation on the discrepancies between package versions found. The discrepancy seems to be between |
I think I can explain a situation where this will happen. Whether this is happening here or not that we need to check. Suppose in |
Another question, as I probably misunderstood you: >>> from packaging import version
>>> version("numpy")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable Are you doing something like this? Why is it failing for me but working for you? |
Ah, sorry, I meant |
for key in DEFAULT_DEPS_TO_SHOW: | ||
key_is_available = _check_soft_dependencies(key, severity="none") | ||
key_is_available = _check_soft_dependencies( | ||
key, severity="none", package_import_alias=PKG_IMPORT_ALIAS |
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.
@fkiraly here key
is sklearn
, as that's what mentioned here:
"sklearn", |
However, _check_soft_dependencies
expect scikit-learn
as the input, not sklearn
.
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.
Yes, I think that should be ok, because _get_deps_info
uses the import path, not the environment specs.
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.
But this is causing key_is_available
to be False
in case of scikit-learn
, do we want that? Is it not expected to be True
for installed packages?
What is your expected value for this?
_check_soft_dependencies("scikit-learn", severity="none", package_import_alias={'scikit-learn':"sklearn"})
On main
, it is True
, on this branch it is False
.
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.
oh, I see! That's the mistake.
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.
attempted fix
This PR optimizes the runtime of
_check_soft_dependencies
, speeding up test collection time, towards #6344.The speed-up comes from using
importlib
find_spec
instead of actually attempting an import and catching the exception.The "suppress std out" argument becomes obsolete, as no output is generated when not importing the module.
This PR also fixes an unreported bug in the
sktime
code base, where the package (PEP 440)scikit-learn
was referred to assklearn
.