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

Overwrite environment deepcopy #83

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions formulae/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# For more info see: https://github.com/pydata/patsy/blob/master/patsy/eval.py
import inspect
import numbers
import dill


class VarLookupDict:
Expand Down Expand Up @@ -75,6 +76,9 @@ def capture(cls, env=0, reference=0):
finally:
del frame

def __deepcopy__(self, memo):
return dill.copy(self)

def _namespace_ids(self):
return [id(n) for n in self._namespaces]

Expand Down
8 changes: 8 additions & 0 deletions formulae/tests/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from formulae.environment import VarLookupDict, Environment
from copy import deepcopy


def test_varlookup_get():
Expand Down Expand Up @@ -85,3 +86,10 @@ def test_evalenv_equality():

env_outer = Environment.capture(1)
assert env != env_outer


def test_evalenv_deepcopy():
a = 1
env = Environment.capture()
clone_env = deepcopy(env)
assert clone_env.namespace["a"] == a
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy>=1.16
pandas>=1.0.0
scipy>=1.5.4
dill>=0.3.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_requirements():

def get_version():
with open(VERSION_FILE, encoding="utf-8") as buff:
exec(buff.read()) # pylint: disable=exec-used
exec(buff.read()) # pylint: disable=exec-used
return vars()["__version__"]


Expand Down