IIIS-Li-Group / OpenFE

OpenFE: automated feature generation with expert-level performance
MIT License
775 stars 99 forks source link

'AttributeError: 'tuple' object has no attribute 'tb_frame' #50

Open gamzeakkurt opened 3 months ago

gamzeakkurt commented 3 months ago

Hi,

I'm using OpenFE to extract features, but when I transform the data after extracting features, I encounter the following error:

'AttributeError: 'tuple' object has no attribute 'tb_frame' .

I'm running Python version 3.11 and have installed all the required dependencies. Despite this, I can't find a solution to the issue. How can I fix this problem?

Code snippet :

> ofe= OpenFE()
> candidate_features_list = get_candidate_features(numerical_features=list(test.columns))
> features = ofe.fit(data=train.drop('Target', axis=1), label=train['Target'],
>                     candidate_features_list=candidate_features_list, metric='multi_logloss', task='classification', stage2_params=params,
>                     min_candidate_features=5000,
>                     n_jobs=n_jobs, n_data_blocks=2, feature_boosting=True)
> 
> train_ft1, test_ft1 = transform(train.drop(target, axis=1), test, features, n_jobs=n_jobs)
cydu007 commented 3 months ago

me too

ZhangTP1996 commented 3 months ago

Which line of code gives this error? I cannot match tb_frame in any code of OpenFE

gamzeakkurt commented 3 months ago

All error information is listed below. Despite properly formatting all feature names, I still encounter this error.

---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.11/site-packages/openfe/utils.py", line 102, in _cal
    _data = pd.read_feather('./openfe_tmp_data.feather', columns=base_features).set_index('openfe_index')
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/pandas/io/feather_format.py", line 129, in read_feather
    return feather.read_feather(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/pyarrow/feather.py", line 226, in read_feather
    return (read_table(
            ^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/pyarrow/feather.py", line 262, in read_table
    table = reader.read_names(columns)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pyarrow/_feather.pyx", line 114, in pyarrow._feather.FeatherReader.read_names
  File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Field named id is not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.11/concurrent/futures/process.py", line 261, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.11/site-packages/openfe/utils.py", line 111, in _cal
    exit()
  File "<frozen _sitebuiltins>", line 26, in __call__
SystemExit: None
"""

The above exception was the direct cause of the following exception:

SystemExit                                Traceback (most recent call last)
    [... skipping hidden 1 frame]

Cell In[14], line 1
----> 1 train_ft1, test_ft1 = transform(train.drop(['target','id'], axis=1), test.drop('id',axis=1), features1, n_jobs=n_jobs)

File /opt/anaconda3/lib/python3.11/site-packages/openfe/utils.py:147, in transform(X_train, X_test, new_features_list, n_jobs, name)
    146 for i, res in enumerate(results):
--> 147     is_cat, d1, d2, f = res.result()
    148     names.append('autoFE_f_%d' % i + name)

File /opt/anaconda3/lib/python3.11/concurrent/futures/_base.py:449, in Future.result(self, timeout)
    448 elif self._state == FINISHED:
--> 449     return self.__get_result()
    451 self._condition.wait(timeout)

File /opt/anaconda3/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
    400 try:
--> 401     raise self._exception
    402 finally:
    403     # Break a reference cycle with the exception in self._exception

SystemExit: None

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
    [... skipping hidden 1 frame]

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py:2121, in InteractiveShell.showtraceback(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)
   2118 if exception_only:
   2119     stb = ['An exception has occurred, use %tb to see '
   2120            'the full traceback.\n']
-> 2121     stb.extend(self.InteractiveTB.get_exception_only(etype,
   2122                                                      value))
   2123 else:
   2125     def contains_exceptiongroup(val):

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:710, in ListTB.get_exception_only(self, etype, value)
    702 def get_exception_only(self, etype, value):
    703     """Only print the exception type and message, without a traceback.
    704 
    705     Parameters
   (...)
    708     value : exception value
    709     """
--> 710     return ListTB.structured_traceback(self, etype, value)

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:568, in ListTB.structured_traceback(self, etype, evalue, etb, tb_offset, context)
    565     chained_exc_ids.add(id(exception[1]))
    566     chained_exceptions_tb_offset = 0
    567     out_list = (
--> 568         self.structured_traceback(
    569             etype,
    570             evalue,
    571             (etb, chained_exc_ids),  # type: ignore
    572             chained_exceptions_tb_offset,
    573             context,
    574         )
    575         + chained_exception_message
    576         + out_list)
    578 return out_list

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:1435, in AutoFormattedTB.structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1433 else:
   1434     self.tb = etb
-> 1435 return FormattedTB.structured_traceback(
   1436     self, etype, evalue, etb, tb_offset, number_of_lines_of_context
   1437 )

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:1326, in FormattedTB.structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1323 mode = self.mode
   1324 if mode in self.verbose_modes:
   1325     # Verbose modes need a full traceback
-> 1326     return VerboseTB.structured_traceback(
   1327         self, etype, value, tb, tb_offset, number_of_lines_of_context
   1328     )
   1329 elif mode == 'Minimal':
   1330     return ListTB.get_exception_only(self, etype, value)

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:1173, in VerboseTB.structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1164 def structured_traceback(
   1165     self,
   1166     etype: type,
   (...)
   1170     number_of_lines_of_context: int = 5,
   1171 ):
   1172     """Return a nice text document describing the traceback."""
-> 1173     formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
   1174                                                            tb_offset)
   1176     colors = self.Colors  # just a shorthand + quicker name lookup
   1177     colorsnormal = colors.Normal  # used a lot

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:1063, in VerboseTB.format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
   1060 assert isinstance(tb_offset, int)
   1061 head = self.prepare_header(str(etype), self.long_header)
   1062 records = (
-> 1063     self.get_records(etb, number_of_lines_of_context, tb_offset) if etb else []
   1064 )
   1066 frames = []
   1067 skipped = 0

File /opt/anaconda3/lib/python3.11/site-packages/IPython/core/ultratb.py:1131, in VerboseTB.get_records(self, etb, number_of_lines_of_context, tb_offset)
   1129 while cf is not None:
   1130     try:
-> 1131         mod = inspect.getmodule(cf.tb_frame)
   1132         if mod is not None:
   1133             mod_name = mod.__name__

AttributeError: 'tuple' object has no attribute 'tb_frame'
ZhangTP1996 commented 3 months ago

Are you using multi-index of the dataframe?

gamzeakkurt commented 3 months ago

No, I am not using a multi-index. After fitting the training data, the DataFrame index was automatically changed to openfe_index. I tried two approaches: transforming the data after dropping openfe_index and transforming it without dropping the index. However, the same issue persisted.

yangfa-zhang commented 3 months ago

metoo