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

Caching a function with a DataFrame parameter doesn't work #530

Open
viksuper555 opened this issue Sep 12, 2023 · 1 comment
Open

Caching a function with a DataFrame parameter doesn't work #530

viksuper555 opened this issue Sep 12, 2023 · 1 comment

Comments

@viksuper555
Copy link

viksuper555 commented Sep 12, 2023

When you cache a function, that has a parameter, which has a default value of a DataFrame raises an Exception.

Minimal reproducible example:

@cache.memoize()
def foo(df=pd.DataFrame(), **kwargs):
print('Not reached')

Traceback:

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
File "init.py", line 839, in decorated_function
cache_key = decorated_function.make_cache_key(f, *args, **kwargs)
File "cache.py", line 30, in make_cache_key
keyargs, keykwargs = self._memoize_kwargs_to_args(
File "init.py", line 651, in _memoize_kwargs_to_args
arg_default = get_arg_default(f, i)
File "flask_caching/utils.py", line 42, in get_arg_default
return arg_def if arg_def != inspect.Parameter.empty else None
File "pandas/core/generic.py", line 1439, in nonzero
raise ValueError(

Expected:

Cache the function correctly.

Environment:

  • Python version: 3.9
  • Flask-Caching version: 2.0.2
@Lxstr
Copy link

Lxstr commented Apr 12, 2024

For anyone seeing this use args_to_ignore=["arg"] parameter.

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

No branches or pull requests

2 participants