Skip to content

Commit

Permalink
fix: revert is_class implementation for seq
Browse files Browse the repository at this point in the history
  • Loading branch information
Willian-Zhang committed Mar 29, 2021
1 parent 265ae97 commit a8bc7d9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ class Sequence(object):

batch_size = 4096 # Defaults to read 4K rows in each batch.

@staticmethod
def is_class(obj):
if isinstance(obj, list):
return False
return hasattr(obj, "__getitem__") and hasattr(obj, "__len__")

@abc.abstractmethod
def __getitem__(self, idx): # type: (Union[int, slice]) -> np.ndarray
"""Return data for given row index.
Expand Down Expand Up @@ -1439,15 +1445,15 @@ def _lazy_init(self, data, label=None, reference=None,
self.__init_from_csc(data, params_str, ref_dataset)
elif isinstance(data, np.ndarray):
self.__init_from_np2d(data, params_str, ref_dataset)
elif isinstance(data, Sequence):
self.__init_from_seqs([data], params_str, ref_dataset)
elif isinstance(data, list) and len(data) > 0:
if all(isinstance(x, np.ndarray) for x in data):
self.__init_from_list_np2d(data, params_str, ref_dataset)
elif all(isinstance(x, Sequence) for x in data):
elif all(Sequence.is_class(x) for x in data):
self.__init_from_seqs(data, params_str, ref_dataset)
else:
raise TypeError('Data list can only be of ndarray or Sequence')
elif Sequence.is_class(data):
self.__init_from_seqs([data], params_str, ref_dataset)
elif isinstance(data, dt_DataTable):
self.__init_from_np2d(data.to_numpy(), params_str, ref_dataset)
else:
Expand Down

0 comments on commit a8bc7d9

Please sign in to comment.