Skip to content

Commit

Permalink
FIX: If a transform function was provided, don't recompile it
Browse files Browse the repository at this point in the history
This helps when the transform function uses it's own cache mechanism, e.g.
gramex.cache.open, and has its own cache. This ensures that the same
transform does not cause a new cache to be created.
  • Loading branch information
sanand0 committed Jan 16, 2024
1 parent 1ea1ac4 commit 7f19afd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gramex/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,9 +1258,14 @@ def alter(
return engine


_transform_cache = {}


def _transform_fn(transform, transform_kwargs):
if callable(transform) and transform_kwargs is not None:
return lambda v: transform(v, **transform_kwargs)
if transform not in _transform_cache:
_transform_cache[transform] = lambda v: transform(v, **transform_kwargs)
return _transform_cache[transform]
return transform


Expand Down

0 comments on commit 7f19afd

Please sign in to comment.