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
base: master
from

Conversation

Projects
None yet
2 participants
@sinhrks
Member

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 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)

This comment has been minimized.

@jreback

jreback Apr 17, 2016

Contributor

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

@jreback

jreback Apr 17, 2016

Contributor

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

This comment has been minimized.

@sinhrks

sinhrks Apr 17, 2016

Member

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

@sinhrks

sinhrks Apr 17, 2016

Member

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

This comment has been minimized.

@jreback

jreback Apr 17, 2016

Contributor

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)

@jreback

jreback Apr 17, 2016

Contributor

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)

This comment has been minimized.

@sinhrks

sinhrks Apr 17, 2016

Member

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

@sinhrks

sinhrks Apr 17, 2016

Member

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

This comment has been minimized.

@jreback

jreback Apr 18, 2016

Contributor

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.

@jreback

jreback Apr 18, 2016

Contributor

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.

This comment has been minimized.

@sinhrks

sinhrks Apr 19, 2016

Member

I see. Added missing checks.

@sinhrks

sinhrks Apr 19, 2016

Member

I see. Added missing checks.

@jreback jreback closed this in 5d8a935 Apr 20, 2016

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Apr 20, 2016

Contributor

thanks!

sparse is really looking nice!

Contributor

jreback commented Apr 20, 2016

thanks!

sparse is really looking nice!

@sinhrks sinhrks deleted the sinhrks:sparse_shift branch Apr 20, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment