Skip to content

Commit

Permalink
[python-package] prefix cast_numpy_array_to_dtype with _ (#5532)
Browse files Browse the repository at this point in the history
  • Loading branch information
Madnex authored Oct 11, 2022
1 parent 4642712 commit c134d3d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def is_numpy_column_array(data: Any) -> bool:
return len(shape) == 2 and shape[1] == 1


def cast_numpy_array_to_dtype(array, dtype):
def _cast_numpy_array_to_dtype(array, dtype):
"""Cast numpy array to given dtype."""
if array.dtype == dtype:
return array
Expand All @@ -215,11 +215,11 @@ def _is_1d_collection(data: Any) -> bool:
def list_to_1d_numpy(data, dtype=np.float32, name='list'):
"""Convert data to numpy 1-D array."""
if _is_numpy_1d_array(data):
return cast_numpy_array_to_dtype(data, dtype)
return _cast_numpy_array_to_dtype(data, dtype)
elif is_numpy_column_array(data):
_log_warning('Converting column-vector to 1d array')
array = data.ravel()
return cast_numpy_array_to_dtype(array, dtype)
return _cast_numpy_array_to_dtype(array, dtype)
elif is_1d_list(data):
return np.array(data, dtype=dtype, copy=False)
elif isinstance(data, pd_Series):
Expand Down Expand Up @@ -252,12 +252,12 @@ def _is_2d_collection(data: Any) -> bool:
def _data_to_2d_numpy(data: Any, dtype: type = np.float32, name: str = 'list') -> np.ndarray:
"""Convert data to numpy 2-D array."""
if _is_numpy_2d_array(data):
return cast_numpy_array_to_dtype(data, dtype)
return _cast_numpy_array_to_dtype(data, dtype)
if _is_2d_list(data):
return np.array(data, dtype=dtype)
if isinstance(data, pd_DataFrame):
_check_for_bad_pandas_dtypes(data.dtypes)
return cast_numpy_array_to_dtype(data.values, dtype)
return _cast_numpy_array_to_dtype(data.values, dtype)
raise TypeError(f"Wrong type({type(data).__name__}) for {name}.\n"
"It should be list of lists, numpy 2-D array or pandas DataFrame")

Expand Down

0 comments on commit c134d3d

Please sign in to comment.