Skip to content

Commit

Permalink
style(linting): py3 type hint for seq
Browse files Browse the repository at this point in the history
  • Loading branch information
Willian-Zhang committed Apr 30, 2021
1 parent cebfaa1 commit a2b0ec9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from functools import wraps
from logging import Logger
from tempfile import NamedTemporaryFile
from typing import Any, Dict, Iterable, List, Set, Union
from typing import Any, Dict, Iterable, List, Set, Union, Tuple

import numpy as np
import scipy.sparse
Expand Down Expand Up @@ -640,7 +640,7 @@ def is_class(obj):
return hasattr(obj, "__getitem__") and hasattr(obj, "__len__")

@abc.abstractmethod
def __getitem__(self, idx): # type: (Union[int, slice]) -> np.ndarray
def __getitem__(self, idx: Union[int, slice]) -> np.ndarray:
"""Return data for given row index.
A basic implementation should look like this:
Expand All @@ -667,7 +667,7 @@ def __getitem__(self, idx): # type: (Union[int, slice]) -> np.ndarray
raise NotImplementedError("remove this line if subclassing")

@abc.abstractmethod
def __len__(self): # type: () -> int
def __len__(self) -> int:
"""Return row count of this sequence."""
raise NotImplementedError

Expand Down Expand Up @@ -1492,8 +1492,7 @@ def _lazy_init(self, data, label=None, reference=None,
# set feature names
return self.set_feature_name(feature_name)

def __yield_row_from(self, seqs, indices):
# type: (List[Sequence], Iterable[int]) -> ...
def __yield_row_from(self, seqs: List[Sequence], indices: Iterable[int]):
offset = 0
seq_id = 0
seq = seqs[seq_id]
Expand All @@ -1507,8 +1506,7 @@ def __yield_row_from(self, seqs, indices):
row = seq[int(id_in_seq)]
yield row if row.flags['OWNDATA'] else row.copy()

def __sample(self, seqs, total_nrow):
# type: (List[Sequence], int, int) -> (np.ndarray, List[np.ndarray])
def __sample(self, seqs: List[Sequence], total_nrow: int) -> Tuple[np.ndarray, List[np.ndarray]]:
"""Sample data from seqs.
Mimics behavior in c_api.cpp:LGBM_DatasetCreateFromMats()
Expand Down Expand Up @@ -1537,8 +1535,7 @@ def __sample(self, seqs, total_nrow):

return filtered, filtered_idx

def __init_from_seqs(self, seqs, params_str, ref_dataset):
# type: (List[Sequence], str, Dataset) -> None
def __init_from_seqs(self, seqs: List[Sequence], params_str: str, ref_dataset: 'Dataset'):
"""
Initialize data from a Sequence object.
Expand Down

0 comments on commit a2b0ec9

Please sign in to comment.