Skip to content

ENH make Random*Sampler accept dask array and dataframe #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid import dask explicitely
  • Loading branch information
glemaitre committed Nov 5, 2020
commit fb3d6a4cffca376cf6e34812b952689e2e157bb4
4 changes: 3 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

def pytest_runtest_setup(item):
fname = item.fspath.strpath
print(item)
if (fname.endswith(os.path.join('keras', '_generator.py')) or
fname.endswith('miscellaneous.rst')):
try:
Expand All @@ -31,7 +32,8 @@ def pytest_runtest_setup(item):
import tensorflow # noqa
except ImportError:
pytest.skip('The tensorflow package is not installed.')
elif "dask" in fname:
elif (fname.endswith(os.path.join("dask", "utils.py")) or
fname.endswith(os.path.join("dask", "_support.py"))):
try:
import dask # noqa
except ImportError:
Expand Down
8 changes: 4 additions & 4 deletions imblearn/dask/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings

from dask import array
import numpy as np
from sklearn.exceptions import DataConversionWarning
from sklearn.utils.multiclass import _is_integral_float

Expand All @@ -9,7 +9,7 @@ def is_multilabel(y):
if not (y.ndim == 2 and y.shape[1] > 1):
return False

labels = array.unique(y).compute()
labels = np.unique(y).compute()

return len(labels) < 3 and (
y.dtype.kind in 'biu' or _is_integral_float(labels)
Expand All @@ -34,12 +34,12 @@ def type_of_target(y):
suffix = ""

# check float and contains non-integer float values
if y.dtype.kind == 'f' and array.any(y != y.astype(int)):
if y.dtype.kind == 'f' and np.any(y != y.astype(int)):
# [.1, .2, 3] or [[.1, .2, 3]] or [[1., .2]] and not [1., 2., 3.]
# NOTE: we don't check for infinite values
return 'continuous' + suffix

labels = array.unique(y).compute()
labels = np.unique(y).compute()
if (len((labels)) > 2) or (y.ndim >= 2 and len(y[0]) > 1):
# [1, 2, 3] or [[1., 2., 3]] or [[1, 2]]
return 'multiclass' + suffix
Expand Down