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

Make formulae reach transformations before outer names #109

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading