numeric_types in python_package/compat.py doesn't include numpy types
In particular, this leads to an issue in during calls of is_1d_list in basics.py, which returns False if e.g. you have a list in which the entries are np.int64 objects. This issue comes up when passing a pandas.DataFrame.index.tolist() object into lgb.Dataset.subset(). Not a crucial bug, as calling np.array() instead of .tolist() circumvents the issue.
As python-package/compat.py already imports numpy, it should be easy to adjust numeric_types to include the various numpy numeric data types. Would be happy to go ahead and do this.
Example:
import lightgbm as lgb
import numpy as np
import pandas as pd
import sys
import platform
print(sys.version)
# 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)]
print(platform.system(), platform.release(), platform.version())
# Windows 2012ServerR2 6.3.9600
test_df = pd.DataFrame({'a':[1,2,3], 'b':[1,1,2]})
print(type(test_df.loc[test_df['b']==1,:].index.tolist()[0]))
# <class 'numpy.int64'>
test_dat = lgb.Dataset(test_df)
test_dat_subset = test_dat.subset(test_df.loc[test_df['b']==1,:].index.tolist())
test_dat_subset.construct()
# TypeError: Wrong type(list) for used_indices, should be list or numpy array
@wxchan
@j-mark-hou you can submit a pr, I think you can directly use function is_numeric to check in is_1d_list.
sounds good i'll do so.
@j-mark-hou any updates ?
sorry by end of week
This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.