Skip to content
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 sklearn/datasets/_twenty_newsgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def fetch_20newsgroups_vectorized(
vectorizer = CountVectorizer(dtype=np.int16)
X_train = vectorizer.fit_transform(data_train.data).tocsr()
X_test = vectorizer.transform(data_test.data).tocsr()
feature_names = vectorizer.get_feature_names()
feature_names = vectorizer.get_feature_names_out()

joblib.dump((X_train, X_test, feature_names), target_file, compress=9)

Expand Down
8 changes: 4 additions & 4 deletions sklearn/utils/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,8 @@ def test_check_pandas_sparse_invalid(ntype1, ntype2):
pd = pytest.importorskip("pandas", minversion="0.25.0")
df = pd.DataFrame(
{
"col1": pd.arrays.SparseArray([0, 1, 0], dtype=ntype1),
"col2": pd.arrays.SparseArray([1, 0, 1], dtype=ntype2),
"col1": pd.arrays.SparseArray([0, 1, 0], dtype=ntype1, fill_value=0),
"col2": pd.arrays.SparseArray([1, 0, 1], dtype=ntype2, fill_value=0),
Comment on lines +1417 to +1418
Copy link
Member Author

@thomasjpfan thomasjpfan Oct 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are causing issues on pandas because the fill value is different depending on the dtype.

https://pandas.pydata.org/docs/reference/api/pandas.arrays.SparseArray.html#pandas-arrays-sparsearray

And this is raising a ValueError on the dev version of pandas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does your change then fix the issue? Can't tell from your explanation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would guess that this fixes the issue but to double-check I pushed an empty commit with [scipy-dev] to trigger the scipy-dev nightly build in this PR.

Copy link
Member Author

@thomasjpfan thomasjpfan Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it fixes the original issue.

There were two issues. With the fix to fetch_20newsgroups_vectorized, it alloed the tests to run, which revealed the pandas issue.

}
)

Expand Down Expand Up @@ -1456,8 +1456,8 @@ def test_check_pandas_sparse_valid(ntype1, ntype2, expected_subtype):
pd = pytest.importorskip("pandas", minversion="0.25.0")
df = pd.DataFrame(
{
"col1": pd.arrays.SparseArray([0, 1, 0], dtype=ntype1),
"col2": pd.arrays.SparseArray([1, 0, 1], dtype=ntype2),
"col1": pd.arrays.SparseArray([0, 1, 0], dtype=ntype1, fill_value=0),
"col2": pd.arrays.SparseArray([1, 0, 1], dtype=ntype2, fill_value=0),
}
)
arr = check_array(df, accept_sparse=["csr", "csc"])
Expand Down