ibis-ml icon indicating copy to clipboard operation
ibis-ml copied to clipboard

feat: enable not fitted check for transform_table() and throw proper exception

Open jitingxu1 opened this issue 11 months ago • 1 comments

The current transform_table throws AttributeError when step is not fitted.

import ibisml as ml
t = ibis.memtable({"a": [1, 2, 3], "b": [2,3,4], "c": [3,4,5]})
step = ml.CountEncode(ml.string())
step.transform_table(t)
----> 1 step.transform_table(t)

File /Users/voltrondata/repos/ibisml/ibisml/steps/encode.py:281, in CountEncode.transform_table(self, table)
    280 def transform_table(self, table: ir.Table) -> ir.Table:
--> 281     for c, value_counts in self.value_counts_.items():
    282         joined = table.left_join(
    283             value_counts, table[c] == value_counts[0], lname="left_{name}", rname=""
    284         )
    285         table = joined.drop(value_counts.columns[0], f"left_{c}").rename(
    286             {c: f"{c}_count"}
    287         )

AttributeError: 'CountEncode' object has no attribute 'value_counts_'

Desired output

Ensure step is fitted when transform_table, otherwise throws proper error, such as NotFitError

jitingxu1 avatar Apr 02 '24 23:04 jitingxu1