Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
c134d3d9
Unverified
Commit
c134d3d9
authored
Oct 11, 2022
by
Madnex
Committed by
GitHub
Oct 11, 2022
Browse files
[python-package] prefix cast_numpy_array_to_dtype with _ (#5532)
parent
46427128
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+5
-5
No files found.
python-package/lightgbm/basic.py
View file @
c134d3d9
...
...
@@ -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
...
...
@@ -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
):
...
...
@@ -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"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment