Skip to content
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

added update_wrapper to NotMemorizedFunc.__init__ #1358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

p610
Copy link

@p610 p610 commented Oct 27, 2022

Quick fix for a problem I recently found. If no cache is used function wrapped with @memory.cache is replaced by NotMemorizedFunc wrapper. This wrapper does nor preserve original properties of the function - in my case name was not available. This makes function behave differently depending whether the cache is defined or not.

Code to fix the problem is a copy paste from https://github.com/p610/joblib/blob/master/joblib/memory.py#L444

Maybe there is a better way to address it.

@codecov
Copy link

codecov bot commented Oct 27, 2022

Codecov Report

Base: 94.02% // Head: 93.95% // Decreases project coverage by -0.06% ⚠️

Coverage data is based on head (c6eff0a) compared to base (854458e).
Patch coverage: 83.33% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1358      +/-   ##
==========================================
- Coverage   94.02%   93.95%   -0.07%     
==========================================
  Files          52       52              
  Lines        7292     7298       +6     
==========================================
+ Hits         6856     6857       +1     
- Misses        436      441       +5     
Impacted Files Coverage Δ
joblib/memory.py 95.02% <66.66%> (-0.49%) ⬇️
joblib/test/test_memory.py 98.59% <100.00%> (+<0.01%) ⬆️
joblib/test/testutils.py 50.00% <0.00%> (-50.00%) ⬇️
joblib/pool.py 87.80% <0.00%> (-0.82%) ⬇️
joblib/parallel.py 96.03% <0.00%> (-0.80%) ⬇️
joblib/_store_backends.py 90.76% <0.00%> (-0.52%) ⬇️
joblib/_parallel_backends.py 94.85% <0.00%> (+1.83%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a worthy change.
I think this was originally not done to make the code of not memorized as light as possible but I think it make things more explicit so I would still do the change.

In order to have the same wrapping behavior, I suggest to make a small wrapping helper and call it in both cases?

try:
functools.update_wrapper(self, func)
except:
"Objects like ufunc don't like that"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put the wrapping code in an helper and use it for both NotMemorizedFunc and MemorizedFunc?

Also, could you also set the doc string of the function, as it is done for MemorizedFunc?

@@ -344,6 +344,10 @@ class NotMemorizedFunc(object):
# Should be a light as possible (for speed)
def __init__(self, func):
self.func = func
try:
functools.update_wrapper(self, func)
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the linting error, could you use except BaseException:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants