Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of mapper with no transformers #179

Open
micahjsmith opened this issue Oct 17, 2018 · 0 comments
Open

Behavior of mapper with no transformers #179

micahjsmith opened this issue Oct 17, 2018 · 0 comments

Comments

@micahjsmith
Copy link

A DataFrameMapper can be initialized and fit with an empty transformer list without errors. But then an error is thrown when transformation is attempted.

  • I would expect (and would find it convenient) that a null mapper would be acceptable, and would transform any X to a np.empty((np.size(X, 0), 0)) or to None. Otherwise this ends up being a fairly annoying special case in application logic.
  • Alternately, if the desired behavior is to throw an error in this situation, it seems that the error is "destined" as soon as the DataFrameMapper is initialized with empty transformer list. So might as well throw the error right away.
In [1]: import pandas as pd
   ...: from sklearn_pandas import DataFrameMapper
   ...:                                                                    
   ...:                                                                    
                                                                                                                                                      
In [2]: X_df = pd.util.testing.makeDataFrame()     
   ...: mapper = DataFrameMapper([], input_df=True)
   ...:                                           
   ...: 
                               
In [3]: mapper.fit(X_df)
Out[3]:                                                                                                                                               
DataFrameMapper(default=False, df_out=False, features=[], input_df=True,
        sparse=False)
                                               
In [4]: mapper.transform(X_df)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-0de258be511f> in <module>()      
----> 1 mapper.transform(X_df)
         
/usr/local/anaconda3/lib/python3.7/site-packages/sklearn_pandas/dataframe_mapper.py in transform(self, X)
    326                 stacked = stacked.toarray()
    327         else:
--> 328             stacked = np.hstack(extracted)
    329
    330         if self.df_out:

/usr/local/anaconda3/lib/python3.7/site-packages/numpy/core/shape_base.py in hstack(tup)
    286         return _nx.concatenate(arrs, 0)
    287     else:
--> 288         return _nx.concatenate(arrs, 1)
    289
    290

ValueError: need at least one array to concatenate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant