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

BUG: Fix inconsistency between the shape properties of SparseSeries and SparseArray (#21126) #21198

Merged
merged 5 commits into from
May 31, 2018

Conversation

nprad
Copy link
Contributor

@nprad nprad commented May 25, 2018

@nprad
Copy link
Contributor Author

nprad commented May 26, 2018

@TomAugspurger I made the changes you suggested. Let me know if there are any changes you need me to make.

@TomAugspurger TomAugspurger added the Sparse Sparse Data Type label May 26, 2018
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Could you also add a release note to 0.23.1

@@ -290,7 +290,9 @@ def __reduce__(self):
"""Necessary for making this object picklable"""
object_state = list(np.ndarray.__reduce__(self))
subclass_state = self.fill_value, self.sp_index
object_state[2] = (object_state[2], subclass_state)
object_state[2] = list(object_state[2])
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: why the changes here? Did we have tests that failed without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, test_pickle was failing.shape is used to pickle objects and the overridden shape does not return the correct value. Therefore, I had to set the shape manually.

@@ -454,6 +454,16 @@ def test_values_asarray(self):
assert_almost_equal(self.arr.to_dense(), self.arr_data)
assert_almost_equal(self.arr.sp_values, np.asarray(self.arr))

def test_shape(self):
out = SparseArray([0, 0, 0, 0, 0])
Copy link
Contributor

Choose a reason for hiding this comment

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

Reference the github issue here as a comment.

@codecov
Copy link

codecov bot commented May 27, 2018

Codecov Report

Merging #21198 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21198      +/-   ##
==========================================
+ Coverage   91.84%   91.84%   +<.01%     
==========================================
  Files         153      153              
  Lines       49505    49543      +38     
==========================================
+ Hits        45466    45504      +38     
  Misses       4039     4039
Flag Coverage Δ
#multiple 90.24% <100%> (ø) ⬆️
#single 41.87% <33.33%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/sparse/array.py 91.38% <100%> (+0.06%) ⬆️
pandas/core/indexes/base.py 96.61% <0%> (-0.08%) ⬇️
pandas/core/frame.py 97.22% <0%> (ø) ⬆️
pandas/util/_decorators.py 82.25% <0%> (ø) ⬆️
pandas/core/series.py 94.12% <0%> (ø) ⬆️
pandas/tseries/offsets.py 97% <0%> (ø) ⬆️
pandas/core/arrays/categorical.py 95.68% <0%> (ø) ⬆️
pandas/core/indexes/datetimelike.py 96.89% <0%> (+0.09%) ⬆️
pandas/core/tools/datetimes.py 84.98% <0%> (+0.54%) ⬆️
pandas/io/formats/printing.py 93.08% <0%> (+3.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c2844a...7cc18c5. Read the comment docs.

@nprad
Copy link
Contributor Author

nprad commented May 27, 2018

Thanks for the review! Made the changes. Let me know if there is anything else that needs to be done.

@@ -290,7 +290,9 @@ def __reduce__(self):
"""Necessary for making this object picklable"""
object_state = list(np.ndarray.__reduce__(self))
subclass_state = self.fill_value, self.sp_index
object_state[2] = (object_state[2], subclass_state)
object_state[2] = list(object_state[2])
object_state[2][1] = super(SparseArray, self).shape
Copy link
Contributor

Choose a reason for hiding this comment

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

this is pretty obtuse, can you make this any more clear

@@ -454,6 +454,17 @@ def test_values_asarray(self):
assert_almost_equal(self.arr.to_dense(), self.arr_data)
assert_almost_equal(self.arr.sp_values, np.asarray(self.arr))

def test_shape(self):
# GH 21126
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add cases that have a fill_value, can you parameterize the tests. also add a test with an object array as well (e.g. steal cases from the constructor tests)

Sparse
^^^^^^

- Bug in :attr:`SparseArray.shape` ignores ``fill_values`` (:issue:`21126`)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you expand on this slightly. maybe

Bzug in SparseArray.shape which previouslvy return a shape that only included the dense values.

@jreback jreback added the Bug label May 29, 2018
@nprad
Copy link
Contributor Author

nprad commented May 31, 2018

Thanks @jreback for the review! Let me know if this is better

@jreback jreback added this to the 0.23.1 milestone May 31, 2018
@jreback jreback merged commit 5348e06 into pandas-dev:master May 31, 2018
@jreback
Copy link
Contributor

jreback commented May 31, 2018

thanks @nprad

jorisvandenbossche pushed a commit to jorisvandenbossche/pandas that referenced this pull request Jun 8, 2018
jorisvandenbossche pushed a commit that referenced this pull request Jun 9, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SparseArray compatibility issues in e.g. sklearn. Series.shape and SparseArray.shape output not consistent.
3 participants