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
17878922
"tests/vscode:/vscode.git/clone" did not exist on "72f5b2f70e06daf428e82f15ba73cdcebae63dc5"
Unverified
Commit
17878922
authored
Mar 16, 2023
by
James Lamb
Committed by
GitHub
Mar 16, 2023
Browse files
[python-package] replace uses of scipy.sparse.issparse() with isinstance() (#5784)
parent
a6bf4ad4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
python-package/lightgbm/basic.py
python-package/lightgbm/basic.py
+7
-7
No files found.
python-package/lightgbm/basic.py
View file @
17878922
...
...
@@ -1011,7 +1011,7 @@ class _InnerPredictor:
)
if
pred_leaf
:
preds
=
preds
.
astype
(
np
.
int32
)
is_sparse
=
scipy
.
sparse
.
issparse
(
preds
)
or
isinstance
(
preds
,
list
)
is_sparse
=
isinstance
(
preds
,
scipy
.
sparse
.
spmatrix
)
or
isinstance
(
preds
,
list
)
if
not
is_sparse
and
preds
.
size
!=
nrow
:
if
preds
.
size
%
nrow
==
0
:
preds
=
preds
.
reshape
(
nrow
,
-
1
)
...
...
@@ -2749,7 +2749,7 @@ class Dataset:
if
self
.
_need_slice
and
self
.
used_indices
is
not
None
and
self
.
reference
is
not
None
:
self
.
data
=
self
.
reference
.
data
if
self
.
data
is
not
None
:
if
isinstance
(
self
.
data
,
np
.
ndarray
)
or
scipy
.
sparse
.
issparse
(
self
.
data
):
if
isinstance
(
self
.
data
,
np
.
ndarray
)
or
isinstance
(
self
.
data
,
scipy
.
sparse
.
spmatrix
):
self
.
data
=
self
.
data
[
self
.
used_indices
,
:]
elif
isinstance
(
self
.
data
,
pd_DataFrame
):
self
.
data
=
self
.
data
.
iloc
[
self
.
used_indices
].
copy
()
...
...
@@ -2901,7 +2901,7 @@ class Dataset:
if
isinstance
(
self
.
data
,
np
.
ndarray
):
if
isinstance
(
other
.
data
,
np
.
ndarray
):
self
.
data
=
np
.
hstack
((
self
.
data
,
other
.
data
))
elif
scipy
.
sparse
.
issparse
(
other
.
data
):
elif
isinstance
(
other
.
data
,
scipy
.
sparse
.
spmatrix
):
self
.
data
=
np
.
hstack
((
self
.
data
,
other
.
data
.
toarray
()))
elif
isinstance
(
other
.
data
,
pd_DataFrame
):
self
.
data
=
np
.
hstack
((
self
.
data
,
other
.
data
.
values
))
...
...
@@ -2909,9 +2909,9 @@ class Dataset:
self
.
data
=
np
.
hstack
((
self
.
data
,
other
.
data
.
to_numpy
()))
else
:
self
.
data
=
None
elif
scipy
.
sparse
.
issparse
(
self
.
data
):
elif
isinstance
(
self
.
data
,
scipy
.
sparse
.
spmatrix
):
sparse_format
=
self
.
data
.
getformat
()
if
isinstance
(
other
.
data
,
np
.
ndarray
)
or
scipy
.
sparse
.
issparse
(
other
.
data
):
if
isinstance
(
other
.
data
,
np
.
ndarray
)
or
isinstance
(
other
.
data
,
scipy
.
sparse
.
spmatrix
):
self
.
data
=
scipy
.
sparse
.
hstack
((
self
.
data
,
other
.
data
),
format
=
sparse_format
)
elif
isinstance
(
other
.
data
,
pd_DataFrame
):
self
.
data
=
scipy
.
sparse
.
hstack
((
self
.
data
,
other
.
data
.
values
),
format
=
sparse_format
)
...
...
@@ -2927,7 +2927,7 @@ class Dataset:
if
isinstance
(
other
.
data
,
np
.
ndarray
):
self
.
data
=
concat
((
self
.
data
,
pd_DataFrame
(
other
.
data
)),
axis
=
1
,
ignore_index
=
True
)
elif
scipy
.
sparse
.
issparse
(
other
.
data
):
elif
isinstance
(
other
.
data
,
scipy
.
sparse
.
spmatrix
):
self
.
data
=
concat
((
self
.
data
,
pd_DataFrame
(
other
.
data
.
toarray
())),
axis
=
1
,
ignore_index
=
True
)
elif
isinstance
(
other
.
data
,
pd_DataFrame
):
...
...
@@ -2941,7 +2941,7 @@ class Dataset:
elif
isinstance
(
self
.
data
,
dt_DataTable
):
if
isinstance
(
other
.
data
,
np
.
ndarray
):
self
.
data
=
dt_DataTable
(
np
.
hstack
((
self
.
data
.
to_numpy
(),
other
.
data
)))
elif
scipy
.
sparse
.
issparse
(
other
.
data
):
elif
isinstance
(
other
.
data
,
scipy
.
sparse
.
spmatrix
):
self
.
data
=
dt_DataTable
(
np
.
hstack
((
self
.
data
.
to_numpy
(),
other
.
data
.
toarray
())))
elif
isinstance
(
other
.
data
,
pd_DataFrame
):
self
.
data
=
dt_DataTable
(
np
.
hstack
((
self
.
data
.
to_numpy
(),
other
.
data
.
values
)))
...
...
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