Fix get_module_by_module_path to support pickle module loaded from arbitrage source file#431
Merged
you-n-g merged 2 commits intomicrosoft:mainfrom May 21, 2021
Merged
Conversation
get_module_by_module_path to support load module from arbitrage source fileget_module_by_module_path to support pickle module loaded from arbitrage source file
you-n-g
reviewed
May 19, 2021
| else: | ||
| if module_path.endswith(".py"): | ||
| module_spec = importlib.util.spec_from_file_location("", module_path) | ||
| module_name = re.sub("^[^a-zA-Z_]+", "", re.sub("[^0-9a-zA-Z_]", "", module_path[:-3].replace("/", "_"))) |
Collaborator
There was a problem hiding this comment.
Why can such behavior solve this problem?
Could you give more docs about it ?
Contributor
Author
There was a problem hiding this comment.
I'm referring the official doc to add module_name in sys.modules to make the loaded module picklable.
https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
The only thing we need is a unique module_name without any possible collision. md5 might be ok but lacks interpretability. Here I consider using the path as the module name.
As module name is also a variable in python, this implementation follows this discussion:
https://stackoverflow.com/questions/3303312/how-do-i-convert-a-string-to-a-valid-variable-name-in-python
qianyun210603
pushed a commit
to qianyun210603/qlib
that referenced
this pull request
Mar 23, 2023
Fix `get_module_by_module_path` to support pickle module loaded from arbitrage source file
you-n-g
pushed a commit
to you-n-g/qlib
that referenced
this pull request
Aug 16, 2025
…soft#431) * set title and round * decision from multiple types * check if decision is true * reformat * remove unused file
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Currently the following script will fail with pickle dump errors:
In this commit, the loaded module is added to
sys.modulesto support pickling.Types of changes