Skip to content
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

Flaky SparseArray tests #23168

Closed
TomAugspurger opened this issue Oct 15, 2018 · 0 comments · Fixed by #23323
Closed

Flaky SparseArray tests #23168

TomAugspurger opened this issue Oct 15, 2018 · 0 comments · Fixed by #23323
Labels
Sparse Sparse Data Type
Milestone

Comments

@TomAugspurger
Copy link
Contributor

pytest pandas/tests/extension/test_sparse.py::TestGetitem::test_getitem_scalar --count=100 -x

Tat fails when the first value is sparse, the fill_value is int, but the .dtype.type is np.int64.

pytest pandas/tests/extension/test_sparse.py::TestMethods::test_unique --count=100 -x 

That fails with the array is all sparse. Fixed by

diff --git a/pandas/core/sparse/array.py b/pandas/core/sparse/array.py
index 15b5118db..17e2bd188 100644
--- a/pandas/core/sparse/array.py
+++ b/pandas/core/sparse/array.py
@@ -561,7 +561,7 @@ class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
             return -1
 
         indices = self.sp_index.to_int_index().indices
-        if indices[0] > 0:
+        if len(indices) == 0 or indices[0] > 0:
             return 0
 
         diff = indices[1:] - indices[:-1]
diff --git a/pandas/tests/sparse/test_array.py b/pandas/tests/sparse/test_array.py
index 0257d9962..5b1afdc7a 100644
--- a/pandas/tests/sparse/test_array.py
+++ b/pandas/tests/sparse/test_array.py
@@ -1065,6 +1065,13 @@ def test_unique_na_fill(arr, fill_value):
     tm.assert_numpy_array_equal(a, b)
 
 
+def test_unique_all_sparse():
+    arr = SparseArray([0, 0])
+    result = arr.unique()
+    expected = SparseArray([0])
+    tm.assert_sp_array_equal(result, expected)
+
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant