MaartenGr / PolyFuzz

Fuzzy string matching, grouping, and evaluation.
https://maartengr.github.io/PolyFuzz/
MIT License
725 stars 68 forks source link

AttributeError: 'PolyFuzz' object has no attribute 'to_list' #55

Closed stereobooster closed 1 year ago

stereobooster commented 1 year ago

Hi! Thank you for this package. This bug occurs in my code: AttributeError: 'PolyFuzz' object has no attribute 'to_list'

Full example is here: https://www.kaggle.com/code/stereobooster/polyfuzz-bug-demo

Versions

Python 3.7.12
polyfuzz 0.4.0

Code

from polyfuzz import PolyFuzz
import pandas as pd

lst = ['Micheal', 'Andrew', 'John', 'Simone', 'Poly', 'Carla', 'Frederik']
df = pd.DataFrame(lst)
df.columns = ['name']

model = PolyFuzz('TF-IDF').match(df['name'])
model.transform(['Tamy'])

Error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_28/2903616377.py in <module>
      7 
      8 model = PolyFuzz('TF-IDF').match(df['name'])
----> 9 model.transform(['Tamy'])

/opt/conda/lib/python3.7/site-packages/polyfuzz/polyfuzz.py in transform(self, from_list)
    233 
    234         if isinstance(self.method, BaseMatcher):
--> 235             matches = self.method.match(from_list, self.to_list, re_train=False)
    236             all_matches[self.method.type] = matches
    237 

AttributeError: 'PolyFuzz' object has no attribute 'to_list'
MaartenGr commented 1 year ago

That happens because you need to do a .fit first before you can apply a .transform. You can find more about that general pipeline here.

stereobooster commented 1 year ago

Thank you. It wasn't obvious to me that those are two different models - one retrieved from match and one from fit