Skip to content

Commit

Permalink
Don't subclass NarwhalsMaterializer
Browse files Browse the repository at this point in the history
  • Loading branch information
stanmart committed Dec 18, 2024
1 parent abfac45 commit 564562f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/tabmat/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas
from formulaic import ModelMatrix, ModelSpec
from formulaic.errors import FactorEncodingError
from formulaic.materializers import NarwhalsMaterializer
from formulaic.materializers import FormulaMaterializer
from formulaic.materializers.types import FactorValues, ScopedTerm
from formulaic.parser.types import Term
from formulaic.transforms import stateful_transform
Expand All @@ -31,7 +31,7 @@
from formulaic.materializers.types.formula_materializer import EncodedTermStructure


class TabmatMaterializer(NarwhalsMaterializer):
class TabmatMaterializer(FormulaMaterializer):
"""Materializer for pandas input and tabmat output."""

REGISTER_NAME = "tabmat"
Expand Down Expand Up @@ -66,6 +66,13 @@ def _init(self):
def data_context(self):
return self.__data_context

@override
def _is_categorical(self, values: Any) -> bool:
if nw.dependencies.is_narwhals_series(values):
if not values.dtype.is_numeric():
return True
return super()._is_categorical(values)

@override
def _encode_constant(self, value, metadata, encoder_state, spec, drop_rows):
series = value * numpy.ones(self.nrows - len(drop_rows))
Expand Down

0 comments on commit 564562f

Please sign in to comment.