Skip to content

Commit edfe180

Browse files
committed
Adding warning for cases not handled
1 parent d865e0f commit edfe180

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

openml/datasets/dataset.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,24 @@ def decode_arff(fh):
368368
def _convert_array_format(data, array_format, attribute_names):
369369
"""Convert a dataset to a given array format.
370370
371-
Converts a non-sparse matrix to numpy array.
372-
Converts a sparse matrix to a sparse dataframe.
371+
Converts to numpy array if data is non-sparse.
372+
Converts to a sparse dataframe if data is sparse.
373373
374374
Parameters
375375
----------
376376
array_format : str {'array', 'dataframe'}
377377
Desired data type of the output
378378
- If array_format='array'
379-
Converts non-sparse numeric data to numpy-array
380-
Enforces numeric encoding of categorical columns
381-
Missing values are represented as NaN in the numpy-array
379+
If data is non-sparse
380+
Converts to numpy-array
381+
Enforces numeric encoding of categorical columns
382+
Missing values are represented as NaN in the numpy-array
383+
else returns data as is
382384
- If array_format='dataframe'
383-
Converts sparse data to sparse dataframe
385+
If data is sparse
386+
Works only on sparse data
387+
Converts sparse data to sparse dataframe
388+
else returns data as is
384389
385390
"""
386391
if array_format == "array" and not scipy.sparse.issparse(data):
@@ -407,8 +412,10 @@ def _encode_if_category(column):
407412
'PyOpenML cannot handle string when returning numpy'
408413
' arrays. Use dataset_format="dataframe".'
409414
)
410-
if array_format == "dataframe" and scipy.sparse.issparse(data):
415+
elif array_format == "dataframe" and scipy.sparse.issparse(data):
411416
return pd.SparseDataFrame(data, columns=attribute_names)
417+
else:
418+
warn("Conversion criteria not satisfied. Returning input data.")
412419
return data
413420

414421
@staticmethod

0 commit comments

Comments
 (0)