77from torch import Tensor
88
99from sdm import Stype , TableTensor
10+ from sdm .nn ._buffer import BufferList
1011from sdm .processing import Processor
1112from sdm .processing .categorical ._categorical import (
12- _CategoryList ,
1313 _check_categorical_codes ,
1414 _check_categories ,
15- _check_category_values ,
1615)
1716from sdm .tensor .categorical import _iter_categories
1817
@@ -27,7 +26,6 @@ class AddCategoryCounts(Processor):
2726 Transform inputs must use the fitted per-column category vocabularies.
2827 Use :class:`~sdm.processing.AlignCategories` before this processor when
2928 training and transform inputs were tensorized independently.
30- Refit after changing category vocabularies; do not modify them in place.
3129
3230 Args:
3331 min_cardinality: A count column is added when its fitted vocabulary
@@ -45,7 +43,7 @@ def __init__(self, min_cardinality: int = 0) -> None:
4543 super ().__init__ ()
4644 self .min_cardinality = min_cardinality
4745 self ._columns : tuple [str , ...] = ()
48- self ._categories = _CategoryList ()
46+ self ._categories : BufferList [ Tensor ] = BufferList ()
4947 self .register_buffer ("_log_counts" , torch .empty (0 ))
5048 self .register_buffer (
5149 "_num_categories" ,
@@ -66,10 +64,6 @@ def _fit(
6664 * ,
6765 generator : torch .Generator | None = None ,
6866 ) -> None :
69- _check_category_values (
70- categories = _iter_categories (table .categorical ),
71- columns = table .categorical_columns ,
72- )
7367 _check_categorical_codes (table )
7468 categorical = table .categorical
7569 self ._columns = tuple (
@@ -107,7 +101,7 @@ def _fit(
107101 value = counts .to (count_dtype ).log1p ().to (dtype ),
108102 )
109103 self ._set_buffer ("_num_categories" , num_categories )
110- self ._categories = _CategoryList (_iter_categories (table .categorical ))
104+ self ._categories = BufferList (_iter_categories (table .categorical ))
111105
112106 def _transform (self , table : TableTensor ) -> TableTensor :
113107 _check_categories (table , self ._categories )
0 commit comments