-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_dense now preserves dtype in SparseArray #10655
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ class TestSparseArray(tm.TestCase): | |
def setUp(self): | ||
self.arr_data = np.array([nan, nan, 1, 2, 3, nan, 4, 5, nan, 6]) | ||
self.arr = SparseArray(self.arr_data) | ||
|
||
self.barr_data = np.array([False, False, True, True, False, False]) | ||
self.barr = SparseArray(self.barr_data, fill_value=False, dtype=bool) | ||
|
||
self.zarr = SparseArray([0, 0, 1, 2, 3, 0, 4, 5, 0, 6], fill_value=0) | ||
|
||
def test_get_item(self): | ||
|
@@ -62,6 +66,10 @@ def test_constructor_copy(self): | |
not_copy.sp_values[:3] = 0 | ||
self.assertTrue((self.arr.sp_values[:3] == 0).all()) | ||
|
||
def test_constructor_match_dtype(self): | ||
res = SparseArray(self.barr_data, dtype=bool) | ||
self.assertEqual(res.dtype, bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually construct what it should look like as an expected and use |
||
|
||
def test_astype(self): | ||
res = self.arr.astype('f8') | ||
res.sp_values[:3] = 27 | ||
|
@@ -81,9 +89,19 @@ def _get_base(values): | |
assert(_get_base(arr2) is _get_base(self.arr)) | ||
|
||
def test_values_asarray(self): | ||
assert_almost_equal(self.arr.values, self.arr_data) | ||
assert_almost_equal(self.arr.to_dense(), self.arr_data) | ||
assert_almost_equal(self.arr.sp_values, np.asarray(self.arr)) | ||
for arr, arr_data in ((self.arr, self.arr_data), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. include the issue number as a comment here |
||
(self.barr, self.barr_data)): | ||
vals = arr.values | ||
assert_almost_equal(vals, arr_data) | ||
self.assertEqual(vals.dtype, arr_data.dtype) | ||
|
||
dense = arr.to_dense() | ||
assert_almost_equal(dense, arr_data) | ||
self.assertEqual(dense.dtype, arr_data.dtype) | ||
|
||
sp_vals = arr.sp_values | ||
assert_almost_equal(sp_vals, np.asarray(arr)) | ||
self.assertEqual(sp_vals.dtype, arr_data.dtype) | ||
|
||
def test_getitem(self): | ||
def _checkit(i): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better way to do this is just use
isnull
which handles all of these things.