8000 fix check_array dtype check for pandas series by amueller · Pull Request #12625 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

fix check_array dtype check for pandas series #12625

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

Merged
merged 7 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion doc/whats_new/_contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

.. _Bertrand Thirion: https://team.inria.fr/parietal/bertrand-thirions-page

.. _Andreas Müller: https://peekaboo-vision.blogspot.com/
.. _Andreas Müller: https://amueller.github.io/

.. _Matthieu Perrot: http://brainvisa.info/biblio/lnao/en/Author/PERROT-M.html

Expand Down
4 changes: 4 additions & 0 deletions doc/whats_new/v0.20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ Changelog
precision issues in :class:`preprocessing.StandardScaler` and
:class:`decomposition.IncrementalPCA` when using float32 datasets.
:issue:`12338` by :user:`bauks <bauks>`.

- |Fix| Calling :func:`utils.check_array` on `pandas.Series`, which
raised an error in 0.20.0, now returns the expected output again.
:issue:`12625` by `Andreas Müller`_

Miscellaneous
.............
Expand Down
8 changes: 8 additions & 0 deletions sklearn/utils/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ def test_suppress_validation():
assert_raises(ValueError, assert_all_finite, X)


def test_check_array_series():
# regression test that check_array works on pandas Series
pd = importorskip("pandas")
res = check_array(pd.Series([1, 2, 3]), ensure_2d=False,
warn_on_dtype=True)
assert_array_equal(res, np.array([1, 2, 3]))


def test_check_dataframe_warns_on_dtype():
# Check that warn_on_dtype also works for DataFrames.
# https://github.com/scikit-learn/scikit-learn/issues/10948
Expand Down
2 changes: 1 addition & 1 deletion sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def check_array(array, accept_sparse=False, accept_large_sparse=True,
# check if the object contains several dtypes (typically a pandas
# DataFrame), and store them. If not, store None.
dtypes_orig = None
if hasattr(array, "dtypes") and hasattr(array, "__array__"):
if hasattr(array, "dtypes") and len(array.dtypes):
dtypes_orig = np.array(array.dtypes)

if dtype_numeric:
Expand Down
0