Skip to content

Commit

Permalink
Make formulae reach transformations before outer names
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicapretto committed Feb 20, 2024
1 parent 9bcd01a commit 7df836c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions formulae/terms/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from formulae.categorical import ENCODINGS, CategoricalBox, Treatment
from formulae.config import config
from formulae.environment import Environment
from formulae.transforms import TRANSFORMS, Proportion, Offset
from formulae.terms.call_utils import CallVarsExtractor
from formulae.utils import is_categorical_dtype
Expand Down Expand Up @@ -100,8 +101,11 @@ def set_type(self, data_mask, env):
env: Environment
The environment where values and functions are taken from.
"""

self.env = env.with_outer_namespace({**TRANSFORMS, **ENCODINGS})
# We initialize an environment where transformations and encodings are available first
# This makes sure formulae uses the internal objects instead of objects that may be
# available in the namespace where 'design_matrices' is called.
transforms_env = Environment([{**TRANSFORMS, **ENCODINGS}])
self.env = transforms_env.with_outer_namespace(env.namespace)
x = self.call.eval(data_mask, self.env)

if is_numeric_dtype(x):
Expand Down

0 comments on commit 7df836c

Please sign in to comment.