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: SparseSeries.shift may raise NameError or TypeError #12908

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Apr 16, 2016

  • no existing issue
  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry

Fixed following bugs on current master. Also, moved TestSparseArrayIndex to test_libsparse

1. shift

pd.SparseSeries([1, 2, 3], fill_value=0).shift(1)
# NameError: global name 'kwds' is not defined

pd.SparseSeries([1, 2, 3]).shift(1)
# TypeError: %d format: a number is required, not float

2. dtype

from pandas.sparse.array import IntIndex
arr = pd.SparseArray([1, 2], sparse_index=IntIndex(4, [1, 2]), dtype=None)
arr.dtype
# dtype('int64')

arr.values
# array([-9223372036854775808,                    1,                    2,
#        -9223372036854775808])

# Expected outputs
arr.dtype
# dtype('float64')

arr.values
# array([ nan,   1.,   2.,  nan])

@sinhrks sinhrks added Bug Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions Sparse Sparse Data Type labels Apr 16, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Apr 16, 2016
@@ -159,6 +22,58 @@ def setUp(self):
self.arr = SparseArray(self.arr_data)
self.zarr = SparseArray([0, 0, 1, 2, 3, 0, 4, 5, 0, 6], fill_value=0)

def test_constructor_dtype(self):
arr = SparseArray([np.nan, 1, 2, np.nan])
self.assertEqual(arr.dtype, np.float64)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would test the fill_value on all of the these (e.g. nan as the default, 0 on next example)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more tests in test_shift_nan. Is this what you mean?

Copy link
Contributor

@jreback jreback Apr 17, 2016

Choose a reason for hiding this comment

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

no I meant that you are asserting the fill_value in some of the tests here (as well as the dtype), but might want to assert fill_value for all (an example will be when we have nan fill values that we DO coerce on creation), e.g. say we have sparse datetimes (we don't really support this ATM)

pd.SparseArray([pd.NaT, pd.Timestamp('20130101'), pd.Timestamp('20130102'), pd.NaT], fill_value=np.nan)

Copy link
Member Author

@sinhrks sinhrks Apr 17, 2016

Choose a reason for hiding this comment

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

@jreback Thanks. ATM we can't create non-numeric SparseArray (#11856). Your example raises TypeError.

Copy link
Contributor

Choose a reason for hiding this comment

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

no I get it. I just want a line that says self.assertTrue(np.isnan(arr.fill_value)) on the tests that don't have this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Added missing checks.

@jreback
Copy link
Contributor

jreback commented Apr 20, 2016

thanks!

sparse is really looking nice!

@sinhrks sinhrks deleted the sparse_shift branch April 20, 2016 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves Sparse Sparse Data Type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants