repo_id
stringclasses
409 values
prefix
large_stringlengths
34
36.3k
target
large_stringlengths
1
498
assertion_type
stringclasses
31 values
difficulty
stringclasses
8 values
test_file
stringlengths
10
121
test_function
stringlengths
1
104
test_class
stringlengths
0
51
lineno
int32
2
11.3k
commit_idx
int32
matthewwardrop/formulaic
import json import os import numpy import numpy as np import pandas import pandas as pd import pytest from formulaic import model_matrix from formulaic.transforms.cubic_spline import ( ExtrapolationError, _get_all_sorted_knots, _map_cyclic, cubic_spline, cyclic_cubic_spline, natural_cubic_spli...
state
assert
variable
tests/transforms/test_cubic_spline.py
test_statefulness
275
null
matthewwardrop/formulaic
import functools from operator import or_ import pytest from formulaic.parser.types import ASTNode, Operator, Token class TestASTNode: def ast_node(self): return ASTNode( Operator( "+", arity=2, precedence=100, to_terms=lambda *...
["a", "b", "c"]
assert
collection
tests/parser/types/test_ast_node.py
test_to_terms
TestASTNode
23
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO from xml.etree.ElementInclude import include import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser import DefaultFormulaParser, DefaultOperatorResolver from formulaic.parser.types import Token from formulaic.parser.types...
names
assert
variable
tests/parser/test_parser.py
test_long_formula
TestFormulaParser
220
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
True
assert
bool_literal
tests/parser/types/test_token.py
test_equality
TestToken
40
null
matthewwardrop/formulaic
import numpy import pandas as pd import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.materializers import FactorValues from formulaic.transforms.hashed import hashed def _compare_factor_values(a, b, comp=lambda x, y: numpy.allclose(x, y)): assert type(a) is
type(b)
assert
func_call
tests/transforms/test_hashed.py
_compare_factor_values
12
null
matthewwardrop/formulaic
from formulaic.parser.types import OrderedSet def test_ordered_set(): assert OrderedSet() == OrderedSet() assert len(OrderedSet()) == 0 assert list(OrderedSet(["a", "a", "z", "b"])) == ["a", "z", "b"] assert repr(OrderedSet(["z", "b", "c"])) == "{'z', 'b', 'c'}" assert OrderedSet(["z", "k"]) | ["...
OrderedSet("k")
assert
func_call
tests/parser/types/test_ordered_set.py
test_ordered_set
12
null
matthewwardrop/formulaic
import numpy import pytest from formulaic.transforms.poly import poly class TestPoly: def data(self): return numpy.linspace(0, 1, 21) def test_basic(self, data): state = {} V = poly(data, _state=state) assert V.shape[1] == 1 # Comparison data copied from R output of...
pytest.approx({0: 0.5})
assert
func_call
tests/transforms/test_poly.py
test_basic
TestPoly
50
null
matthewwardrop/formulaic
import re import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.errors import DataMismatchWarning from formulaic.materializers import FactorValues from formulaic.model_spec import ModelSpec from formulaic.transforms.contrasts import ( ContrastsR...
state
assert
variable
tests/transforms/test_contrasts.py
test_basic_usage_and_state
TestContrastsTransform
63
null
matthewwardrop/formulaic
import json import os import numpy import numpy as np import pandas import pandas as pd import pytest from formulaic import model_matrix from formulaic.transforms.cubic_spline import ( ExtrapolationError, _get_all_sorted_knots, _map_cyclic, cubic_spline, cyclic_cubic_spline, natural_cubic_spli...
[1, 2, 3])
assert_*
collection
tests/transforms/test_cubic_spline.py
test_get_all_sorted_knots
95
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
(3, 5)
assert
collection
tests/materializers/test_pandas.py
test_na_handling
TestPandasMaterializer
227
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
scoped_term.factors
assert
complex_expr
tests/materializers/types/test_scoped_term.py
test_copy
TestScopedTerm
42
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
2
assert
numeric_literal
tests/materializers/test_pandas.py
test_data_conversion
TestPandasMaterializer
135
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
"+"
assert
string_literal
tests/parser/types/test_token.py
test_equality
TestToken
32
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
["a"]
assert
collection
tests/materializers/test_pandas.py
test_data_conversion
TestPandasMaterializer
123
null
matthewwardrop/formulaic
import numpy import pandas from scipy.sparse import csc_matrix from formulaic.utils.sparse import categorical_encode_series_to_sparse_csc_matrix def test_sparse_category_encoding(): data = pandas.Series(list("abcdefgabcdefg")) levels, encoded = categorical_encode_series_to_sparse_csc_matrix(data) ( ...
(14, 7)
assert
collection
tests/utils/test_sparse.py
test_sparse_category_encoding
26
null
matthewwardrop/formulaic
from formulaic.parser.types import OrderedSet def test_ordered_set(): assert OrderedSet() == OrderedSet() assert len(OrderedSet()) ==
0
assert
numeric_literal
tests/parser/types/test_ordered_set.py
test_ordered_set
6
null
matthewwardrop/formulaic
import re from pyexpat import model import numpy import pandas import pytest import scipy.sparse from formulaic import Formula, ModelMatrices, ModelMatrix, ModelSpec, ModelSpecs from formulaic.materializers.base import FormulaMaterializerMeta from formulaic.materializers.pandas import PandasMaterializer from formulai...
{}
assert
collection
tests/test_model_spec.py
test_empty
TestModelSpec
183
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pytest from formulaic.utils.structured import Structured class TestStructured: def test_access_structure(self): s = Structured("Hello", key="asd") assert s.root == "Hello" assert s[None] == "Hello" assert s.key == "asd" ...
"a"
assert
string_literal
tests/parser/types/test_structured.py
test_access_structure
TestStructured
49
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pandas import pytest from formulaic import Formula, SimpleFormula, StructuredFormula from formulaic.errors import FormulaInvalidError, FormulaMaterializerInvalidError from formulaic.parser.types.factor import Factor from formulaic.parser.types.term import Term fro...
["a"]
assert
collection
tests/test_formula.py
test_structured
TestFormula
174
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_sort(self): ...
c
assert
variable
tests/parser/types/test_factor.py
test_sort
TestFactor
36
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
hash("b:c")
assert
func_call
tests/parser/types/test_term.py
test_hash
TestTerm
27
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
None
assert
none_literal
tests/parser/types/test_token.py
test_get_source_context
TestToken
73
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import ScopedFactor from formulaic.parser.types import Factor class TestScopedFactor: def scoped_factor(self): return ScopedFactor(Factor("a")) def scoped_factor_reduced(self): return ScopedFactor(Factor("a"), reduced=True) def test_sort(...
TypeError)
pytest.raises
variable
tests/materializers/types/test_scoped_factor.py
test_sort
TestScopedFactor
33
null
matthewwardrop/formulaic
import re import narwhals.stable.v1 as nw import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.materializers import NarwhalsMaterializer NARWHALS_TESTS = { "a": (["Intercept", "a"], ["Intercept", "a"]), "A": ( ["Intercept", "A[T.b]...
2
assert
numeric_literal
tests/materializers/test_narwhals.py
test_data_wrapper
TestNarwhalsMaterializer
61
null
matthewwardrop/formulaic
import numpy import pandas from formulaic import model_matrix from formulaic.transforms.contrasts import TreatmentContrasts from formulaic.transforms.patsy_compat import Treatment, standardize from formulaic.transforms.scale import scale def test_Treatment(): assert isinstance(Treatment(reference="a"), TreatmentC...
"a"
assert
string_literal
tests/transforms/test_patsy_compat.py
test_Treatment
18
null
matthewwardrop/formulaic
import numpy import pytest from formulaic.transforms.poly import poly class TestPoly: def data(self): return numpy.linspace(0, 1, 21) def test_basic(self, data): state = {} V = poly(data, _state=state) assert V.shape[1] == 1 # Comparison data copied from R output of...
pytest.approx({0: 21.0, 1: 1.925})
assert
func_call
tests/transforms/test_poly.py
test_basic
TestPoly
51
null
matthewwardrop/formulaic
from formulaic.parser.types import OrderedSet def test_ordered_set(): assert OrderedSet() ==
OrderedSet()
assert
func_call
tests/parser/types/test_ordered_set.py
test_ordered_set
5
null
matthewwardrop/formulaic
import re from pyexpat import model import numpy import pandas import pytest import scipy.sparse from formulaic import Formula, ModelMatrices, ModelMatrix, ModelSpec, ModelSpecs from formulaic.materializers.base import FormulaMaterializerMeta from formulaic.materializers.pandas import PandasMaterializer from formulai...
[3]
assert
collection
tests/test_model_spec.py
test_get_linear_constraints
TestModelSpec
174
null
matthewwardrop/formulaic
import pandas import pytest from formulaic import model_matrix from formulaic.errors import FactorEvaluationError def global_test(x): return x**2 class TestSugar: def data(self): return pandas.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}) def test_model_matrix(self, data): ...
[16, 25, 36]
assert
collection
tests/test_sugar.py
test_model_matrix
TestSugar
23
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
{"a"}
assert
collection
tests/parser/types/test_token.py
test_required_variables
TestToken
100
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, FactorValues from formulaic.parser.types import Factor class TestEvaluatedFactor: def ev_factor(self): return EvaluatedFactor(Factor("a"), FactorValues([1, 2, 3], kind="numerical")) def test_repr(self, ev_factor): asse...
repr(Factor("a"))
assert
func_call
tests/materializers/types/test_evaluated_factor.py
test_repr
TestEvaluatedFactor
17
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
2
assert
numeric_literal
tests/parser/types/test_term.py
test_degree
TestTerm
48
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
"a+"
assert
string_literal
tests/parser/types/test_token.py
test_update
TestToken
23
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO from xml.etree.ElementInclude import include import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser import DefaultFormulaParser, DefaultOperatorResolver from formulaic.parser.types import Token from formulaic.parser.types...
repr(PARSER.get_ast(expr))
assert
func_call
tests/parser/test_parser.py
test_long_formula
TestFormulaParser
217
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_equality(self...
"a"
assert
string_literal
tests/parser/types/test_factor.py
test_equality
TestFactor
27
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
scoped_term.scale
assert
complex_expr
tests/materializers/types/test_scoped_term.py
test_copy
TestScopedTerm
43
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_sort(self): ...
b
assert
variable
tests/parser/types/test_factor.py
test_sort
TestFactor
35
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pandas import pytest from formulaic import Formula, SimpleFormula, StructuredFormula from formulaic.errors import FormulaInvalidError, FormulaMaterializerInvalidError from formulaic.parser.types.factor import Factor from formulaic.parser.types.term import Term fro...
{"a"}
assert
collection
tests/test_formula.py
test_required_variables
TestFormula
265
null
matthewwardrop/formulaic
import re import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.errors import DataMismatchWarning from formulaic.materializers import FactorValues from formulaic.model_spec import ModelSpec from formulaic.transforms.contrasts import ( ContrastsR...
"b"
assert
string_literal
tests/transforms/test_contrasts.py
test_basic
TestSASContrasts
532
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, FactorValues from formulaic.parser.types import Factor class TestEvaluatedFactor: def ev_factor(self): return EvaluatedFactor(Factor("a"), FactorValues([1, 2, 3], kind="numerical")) def test_attributes(self, ev_factor): ...
Factor.Kind.NUMERICAL
assert
complex_expr
tests/materializers/types/test_evaluated_factor.py
test_attributes
TestEvaluatedFactor
13
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO from xml.etree.ElementInclude import include import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser import DefaultFormulaParser, DefaultOperatorResolver from formulaic.parser.types import Token from formulaic.parser.types...
resolver.__dict__
assert
complex_expr
tests/parser/test_parser.py
test_pickleable
TestDefaultOperatorResolver
339
null
matthewwardrop/formulaic
import pytest from formulaic.utils.iterators import peekable_iter def test_peekable_iter(): it = peekable_iter([1, 2, 3, 4, 5, 6]) assert it.peek() == 1 assert it._next ==
[1]
assert
collection
tests/utils/test_iterators.py
test_peekable_iter
10
null
matthewwardrop/formulaic
import re import narwhals.stable.v1 as nw import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.materializers import NarwhalsMaterializer NARWHALS_TESTS = { "a": (["Intercept", "a"], ["Intercept", "a"]), "A": ( ["Intercept", "A[T.b]...
tests[1]
assert
complex_expr
tests/materializers/test_narwhals.py
test_get_model_matrix
TestNarwhalsMaterializer
90
null
matthewwardrop/formulaic
import re from pyexpat import model import numpy import pandas import pytest import scipy.sparse from formulaic import Formula, ModelMatrices, ModelMatrix, ModelSpec, ModelSpecs from formulaic.materializers.base import FormulaMaterializerMeta from formulaic.materializers.pandas import PandasMaterializer from formulai...
[1]
assert
collection
tests/test_model_spec.py
test_get_column_indices
TestModelSpec
111
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO from xml.etree.ElementInclude import include import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser import DefaultFormulaParser, DefaultOperatorResolver from formulaic.parser.types import Token from formulaic.parser.types...
Structured([])
assert
func_call
tests/parser/test_parser.py
test_empty_formula
TestFormulaParser
210
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
["c"]
assert
collection
tests/materializers/test_pandas.py
test_index_maintained
TestPandasMaterializer
396
null
matthewwardrop/formulaic
import re import numpy import pandas as pd import pytest from formulaic import model_matrix from formulaic.errors import FactorEvaluationError from formulaic.transforms.basis_spline import basis_spline class TestBasisSpline: def data(self): return numpy.linspace(0, 1, 21) def test_df(self, data): ...
5
assert
numeric_literal
tests/transforms/test_basis_spline.py
test_df
TestBasisSpline
212
null
matthewwardrop/formulaic
import numpy import pytest from formulaic.transforms.poly import poly class TestPoly: def data(self): return numpy.linspace(0, 1, 21) def test_degree(self, data): state = {} V = poly(data, degree=3, _state=state) assert V.shape[1] == 3 # Comparison data copied from ...
pytest.approx({0: 0.5, 1: 0.5, 2: 0.5})
assert
func_call
tests/transforms/test_poly.py
test_degree
TestPoly
98
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, FactorValues from formulaic.parser.types import Factor class TestEvaluatedFactor: def ev_factor(self): return EvaluatedFactor(Factor("a"), FactorValues([1, 2, 3], kind="numerical")) def test_sort(self, ev_factor): asser...
TypeError)
pytest.raises
variable
tests/materializers/types/test_evaluated_factor.py
test_sort
TestEvaluatedFactor
30
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
True
assert
bool_literal
tests/materializers/test_pandas.py
test__is_categorical
TestPandasMaterializer
295
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
0
assert
numeric_literal
tests/materializers/test_pandas.py
test_empty
TestPandasMaterializer
375
null
matthewwardrop/formulaic
import re import numpy import pytest from formulaic.utils.stateful_transforms import stateful_eval, stateful_transform def dummy_transform(data, _state=None, _spec=None, _metadata=None): if _metadata is not None: _metadata["added"] = True if "data" not in _state: _state["data"] = data ret...
True
assert
bool_literal
tests/utils/test_stateful_transforms.py
test_stateful_transform
23
null
matthewwardrop/formulaic
import copy import pickle import numpy import pandas import pytest from formulaic import ( FactorValues, ModelMatrices, ModelMatrix, ModelSpec, ModelSpecs, model_matrix, ) def test_factor_values_copy(): d = {"1": object()} f = FactorValues(d, drop_field="test") f2 = copy.copy(f) ...
d["1"]
assert
complex_expr
tests/test_model_matrix.py
test_factor_values_copy
48
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import ModelMatrices from formulaic.errors import ( FactorEncodingError, FactorEvaluationError, FormulaMaterializationError, ) from formulaic.materializers import PandasMa...
False
assert
bool_literal
tests/materializers/test_pandas.py
test__is_categorical
TestPandasMaterializer
294
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_to_terms(self...
Factor("a")
assert
func_call
tests/parser/types/test_factor.py
test_to_terms
TestFactor
51
null
matthewwardrop/formulaic
import pytest from formulaic.utils.iterators import peekable_iter def test_peekable_iter(): it = peekable_iter([1, 2, 3, 4, 5, 6]) assert it.peek() == 1 assert it._next == [1] assert next(it) == 1 assert it._next ==
[]
assert
collection
tests/utils/test_iterators.py
test_peekable_iter
12
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
{"a", "b"}
assert
collection
tests/materializers/types/test_scoped_term.py
test_variables
TestScopedTerm
62
null
matthewwardrop/formulaic
import json import os import numpy import numpy as np import pandas import pandas as pd import pytest from formulaic import model_matrix from formulaic.transforms.cubic_spline import ( ExtrapolationError, _get_all_sorted_knots, _map_cyclic, cubic_spline, cyclic_cubic_spline, natural_cubic_spli...
"cc"
assert
string_literal
tests/transforms/test_cubic_spline.py
test_crs_compat_with_r
206
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
token_b
assert
variable
tests/parser/types/test_token.py
test_ranking
TestToken
47
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
1
assert
numeric_literal
tests/materializers/types/test_scoped_term.py
test_equality
TestScopedTerm
37
null
matthewwardrop/formulaic
import json import os import numpy import numpy as np import pandas import pandas as pd import pytest from formulaic import model_matrix from formulaic.transforms.cubic_spline import ( ExtrapolationError, _get_all_sorted_knots, _map_cyclic, cubic_spline, cyclic_cubic_spline, natural_cubic_spli...
[3, 8])
assert_*
collection
tests/transforms/test_cubic_spline.py
test_get_all_sorted_knots
89
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pytest from formulaic.utils.structured import Structured class TestStructured: def test_constructor(self): obj = object() assert Structured(obj).root is obj assert Structured(obj, key="asd").root is obj assert len(Structured(o...
2
assert
numeric_literal
tests/parser/types/test_structured.py
test_constructor
TestStructured
15
null
matthewwardrop/formulaic
import json import os import numpy import numpy as np import pandas import pandas as pd import pytest from formulaic import model_matrix from formulaic.transforms.cubic_spline import ( ExtrapolationError, _get_all_sorted_knots, _map_cyclic, cubic_spline, cyclic_cubic_spline, natural_cubic_spli...
re_res[i])
assert_*
complex_expr
tests/transforms/test_cubic_spline.py
test_alternative_extrapolation
363
null
matthewwardrop/formulaic
import copy import pickle from formulaic.materializers.types import FactorValues def test_factor_values_pickle(): d = {"1": object()} f = FactorValues(d, drop_field="test") f2 = pickle.loads(pickle.dumps(f)) assert list(f2.__wrapped__.keys()) ==
list(d.keys())
assert
func_call
tests/materializers/types/test_factor_values.py
test_factor_values_pickle
27
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import ScopedFactor from formulaic.parser.types import Factor class TestScopedFactor: def scoped_factor(self): return ScopedFactor(Factor("a")) def scoped_factor_reduced(self): return ScopedFactor(Factor("a"), reduced=True) def test_repr(...
"a-"
assert
string_literal
tests/materializers/types/test_scoped_factor.py
test_repr
TestScopedFactor
18
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO from xml.etree.ElementInclude import include import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser import DefaultFormulaParser, DefaultOperatorResolver from formulaic.parser.types import Token from formulaic.parser.types...
new_tbl
assert
variable
tests/parser/test_parser.py
test_feature_flags
TestDefaultOperatorResolver
347
null
matthewwardrop/formulaic
import re import pandas import pyarrow import pytest from formulaic.errors import FactorEncodingError, FormulaMaterializerNotFoundError from formulaic.materializers.base import FormulaMaterializer from formulaic.materializers.narwhals import NarwhalsMaterializer from formulaic.materializers.pandas import PandasMateri...
{"a:b": 6}
assert
collection
tests/materializers/test_base.py
test__get_columns_for_term
TestFormulaMaterializer
217
null
matthewwardrop/formulaic
from formulaic.utils.layered_mapping import LayeredMapping from formulaic.utils.variables import Variable, get_expression_variables def test_get_expression_variables(): assert get_expression_variables("a + b", {}) ==
{"a", "b"}
assert
collection
tests/utils/test_variables.py
test_get_expression_variables
6
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
(1, 1)
assert
collection
tests/parser/types/test_token.py
test_update
TestToken
27
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
"a:b"
assert
string_literal
tests/materializers/types/test_scoped_term.py
test_repr
TestScopedTerm
27
null
matthewwardrop/formulaic
import functools import itertools import pytest from formulaic.errors import FormulaSyntaxError from formulaic.parser import DefaultOperatorResolver from formulaic.parser.algos.tokenize import tokenize from formulaic.parser.algos.tokens_to_ast import tokens_to_ast from formulaic.parser.types import Operator @pytest....
flattened
assert
variable
tests/parser/algos/test_tokens_to_ast.py
test_formula_to_ast
85
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pytest from formulaic.utils.structured import Structured class TestStructured: def test_access_structure(self): s = Structured("Hello", key="asd") assert s.root == "Hello" assert s[None] == "Hello" assert s.key == "asd" ...
1
assert
numeric_literal
tests/parser/types/test_structured.py
test_access_structure
TestStructured
52
null
matthewwardrop/formulaic
import numpy import pytest from formulaic.transforms.poly import poly class TestPoly: def data(self): return numpy.linspace(0, 1, 21) def test_basic(self, data): state = {} V = poly(data, _state=state) assert V.shape[1] ==
1
assert
numeric_literal
tests/transforms/test_poly.py
test_basic
TestPoly
16
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Term, Token class TestToken: def token_a(self): return Token("a", kind="name") def token_b(self): return Token( "log(x)", kind="python", source="y ~ log(x)", source_start=4, source_end=9 ) def token_c(self): re...
{"x"}
assert
collection
tests/parser/types/test_token.py
test_required_variables
TestToken
101
null
matthewwardrop/formulaic
import numpy import pandas from scipy.sparse import csc_matrix from formulaic.utils.sparse import categorical_encode_series_to_sparse_csc_matrix def test_sparse_category_encoding(): data = pandas.Series(list("abcdefgabcdefg")) levels, encoded = categorical_encode_series_to_sparse_csc_matrix(data) ( ...
(0, 0)
assert
collection
tests/utils/test_sparse.py
test_sparse_category_encoding
63
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_hash(self): ...
hash("a")
assert
func_call
tests/parser/types/test_factor.py
test_hash
TestFactor
43
null
matthewwardrop/formulaic
import copy import pickle import numpy import pandas import pytest from formulaic import ( FactorValues, ModelMatrices, ModelMatrix, ModelSpec, ModelSpecs, model_matrix, ) def test_factor_values_copy(): d = {"1": object()} f = FactorValues(d, drop_field="test") f2 = copy.copy(f) ...
"test"
assert
string_literal
tests/test_model_matrix.py
test_factor_values_copy
49
null
matthewwardrop/formulaic
import re import narwhals.stable.v1 as nw import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.materializers import NarwhalsMaterializer NARWHALS_TESTS = { "a": (["Intercept", "a"], ["Intercept", "a"]), "A": ( ["Intercept", "A[T.b]...
0
assert
numeric_literal
tests/materializers/test_narwhals.py
test_empty
TestNarwhalsMaterializer
150
null
matthewwardrop/formulaic
import pandas import pytest from formulaic import model_matrix from formulaic.errors import FactorEvaluationError def global_test(x): return x**2 class TestSugar: def data(self): return pandas.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}) def test_model_matrix(self, data): ...
[1, 4, 9]
assert
collection
tests/test_sugar.py
test_model_matrix
TestSugar
22
null
matthewwardrop/formulaic
import numpy import pandas import pytest import scipy.sparse from formulaic import FactorValues from formulaic.utils.cast import as_columns def test_as_columns(): assert as_columns(1) == 1 assert as_columns([1, 2, 3, 4]) == [1, 2, 3, 4] # Check pandas types series = pandas.Series([1, 2, 3]) asser...
True
assert
bool_literal
tests/utils/test_cast.py
test_as_columns
54
null
matthewwardrop/formulaic
import re import pandas import pyarrow import pytest from formulaic.errors import FactorEncodingError, FormulaMaterializerNotFoundError from formulaic.materializers.base import FormulaMaterializer from formulaic.materializers.narwhals import NarwhalsMaterializer from formulaic.materializers.pandas import PandasMateri...
["a", "b"]
assert
collection
tests/materializers/test_base.py
test__enforce_structure
TestFormulaMaterializer
172
null
matthewwardrop/formulaic
import re import narwhals.stable.v1 as nw import numpy import pandas import pytest import scipy.sparse as spsparse from formulaic import model_matrix from formulaic.materializers import NarwhalsMaterializer NARWHALS_TESTS = { "a": (["Intercept", "a"], ["Intercept", "a"]), "A": ( ["Intercept", "A[T.b]...
{"a", "A"}
assert
collection
tests/materializers/test_narwhals.py
test_data_wrapper
TestNarwhalsMaterializer
60
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
term1
assert
variable
tests/parser/types/test_term.py
test_equality
TestTerm
30
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Operator class TestOperator: def test_repr(self): assert repr(Operator("op", arity=2, precedence=100)) ==
"op"
assert
string_literal
tests/parser/types/test_operator.py
test_repr
TestOperator
31
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
"b:c"
assert
string_literal
tests/parser/types/test_term.py
test_equality
TestTerm
31
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_attributes(se...
Factor.EvalMethod.LOOKUP
assert
complex_expr
tests/parser/types/test_factor.py
test_attributes
TestFactor
23
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_equality(self...
Factor("a", kind="numerical")
assert
func_call
tests/parser/types/test_factor.py
test_equality
TestFactor
29
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
1
assert
numeric_literal
tests/parser/types/test_term.py
test_equality
TestTerm
33
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor, Term from formulaic.parser.types.ordered_set import OrderedSet class TestTerm: def term1(self): return Term([Factor("c"), Factor("b")]) def term2(self): return Term([Factor("c"), Factor("d")]) def term3(self): return Term(...
term3
assert
variable
tests/parser/types/test_term.py
test_sort
TestTerm
37
null
matthewwardrop/formulaic
import re import pytest from formulaic.errors import FormulaParsingError, FormulaSyntaxError from formulaic.parser.types import Operator, OperatorResolver, Token OPERATOR_PLUS = Operator("+", arity=2, precedence=100, fixity="infix") OPERATOR_UNARY_MINUS = Operator("-", arity=1, precedence=100, fixity="prefix") OPERA...
FormulaSyntaxError, match=re.escape("Unknown operator '&'"))
pytest.raises
func_call
tests/parser/types/test_operator_resolver.py
test_resolve
TestOperatorResolver
34
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import FormulaParser FORMULA_TO_TOKENS = { "": [], " ": [], " \n": [], "1": ["1"], "a": ["a"], "a ~ b": ["a", "~", "b"], "a ~": ["a", "~"], "~ 1 + a": ["~", "1", "+", "a"], "0": ["0"], "0 ~": ["0", "~"], } PARSER = FormulaParser(operat...
list(PARSER.parse("a ~ b", target=target.value))
assert
func_call
tests/parser/types/test_formula_parser.py
test_parse_target_equivalence
TestFormulaParser
34
null
matthewwardrop/formulaic
import re import numpy import pandas import pytest import scipy.sparse from formulaic.materializers.types import FactorValues from formulaic.utils.null_handling import drop_rows, find_nulls def test_drop_rows(): assert drop_rows([1, 2, 3], [1]) ==
[1, 3]
assert
collection
tests/utils/test_null_handling.py
test_drop_rows
60
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pytest from formulaic.utils.structured import Structured class TestStructured: def test_constructor(self): obj = object() assert Structured(obj).root is
obj
assert
variable
tests/parser/types/test_structured.py
test_constructor
TestStructured
13
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_equality(self...
1
assert
numeric_literal
tests/parser/types/test_factor.py
test_equality
TestFactor
28
null
matthewwardrop/formulaic
import numpy import pandas from scipy.sparse import csc_matrix from formulaic.utils.sparse import categorical_encode_series_to_sparse_csc_matrix def test_sparse_category_encoding(): data = pandas.Series(list("abcdefgabcdefg")) levels, encoded = categorical_encode_series_to_sparse_csc_matrix(data) ( ...
(3, 0)
assert
collection
tests/utils/test_sparse.py
test_sparse_category_encoding
70
null
matthewwardrop/formulaic
import numpy import pandas import pytest import scipy.sparse from formulaic import FactorValues from formulaic.utils.cast import as_columns def test_as_columns(): assert as_columns(1) == 1 assert as_columns([1, 2, 3, 4]) == [1, 2, 3, 4] # Check pandas types series = pandas.Series([1, 2, 3]) asse...
series
assert
variable
tests/utils/test_cast.py
test_as_columns
16
null
matthewwardrop/formulaic
import pytest from formulaic.parser.types import Factor class TestFactor: def factor_unknown(self): return Factor("unknown") def factor_literal(self): return Factor('"string"', kind="literal") def factor_lookup(self): return Factor("a", kind="lookup") def test_attributes(se...
Factor.Kind.UNKNOWN
assert
complex_expr
tests/parser/types/test_factor.py
test_attributes
TestFactor
20
null
matthewwardrop/formulaic
import pytest from formulaic.materializers.types import EvaluatedFactor, ScopedFactor, ScopedTerm from formulaic.parser.types import Factor from formulaic.utils.variables import Variable class TestScopedTerm: def scoped_term(self): return ScopedTerm( [ ScopedFactor( ...
hash(("a", "b"))
assert
func_call
tests/materializers/types/test_scoped_term.py
test_hash
TestScopedTerm
31
null
matthewwardrop/formulaic
import pickle import re from io import BytesIO import pytest from formulaic.utils.structured import Structured class TestStructured: def test_access_structure(self): s = Structured("Hello", key="asd") assert s.root == "Hello" assert s[None] == "Hello" assert s.key ==
"asd"
assert
string_literal
tests/parser/types/test_structured.py
test_access_structure
TestStructured
32
null
matthewwardrop/formulaic
import copy from formulaic.utils.sentinels import MISSING, UNSET, Sentinel def test_missing(): assert MISSING is Sentinel.MISSING assert UNSET is Sentinel.UNSET assert MISSING is not
UNSET
assert
variable
tests/utils/test_sentinels.py
test_missing
9
null