-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Segfault with pd.tslib.get_period_field FIX #4520
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
class TestPeriodField(unittest.TestCase): | ||
_multiprocess_can_split_ = True | ||
|
||
def test_get_period_field_raises_on_out_of_range(self): | ||
self.assertRaises(ValueError, pd.tslib.get_period_field, -1, 0, 0) | ||
|
||
def test_get_period_field_array_raises_on_out_of_range(self): | ||
self.assertRaises(ValueError, pd.tslib.get_period_field_arr, -1, np.empty(1), 0) | ||
|
||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], | ||
exit=False) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2417,6 +2417,8 @@ ctypedef int (*accessor)(int64_t ordinal, int freq) except INT32_MIN | |
|
||
def get_period_field(int code, int64_t value, int freq): | ||
cdef accessor f = _get_accessor_func(code) | ||
if <long>f == <long>NULL: | ||
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. you should be able to say 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. looks like http://docs.cython.org/src/tutorial/clibraries.html#testing-the-result so maybe change to also can you change the error message to say something about periods? something simple like "Unrecognizable period code: {the_code}" |
||
raise ValueError('Unrecognized code: %s' % code) | ||
return f(value, freq) | ||
|
||
def get_period_field_arr(int code, ndarray[int64_t] arr, int freq): | ||
|
@@ -2426,6 +2428,8 @@ def get_period_field_arr(int code, ndarray[int64_t] arr, int freq): | |
accessor f | ||
|
||
f = _get_accessor_func(code) | ||
if <long>f == <long>NULL: | ||
raise ValueError('Unrecognized code: %s' % code) | ||
|
||
sz = len(arr) | ||
out = np.empty(sz, dtype=np.int64) | ||
|
@@ -2460,8 +2464,7 @@ cdef accessor _get_accessor_func(int code): | |
return &pday_of_year | ||
elif code == 10: | ||
return &pweekday | ||
else: | ||
raise ValueError('Unrecognized code: %s' % code) | ||
return NULL | ||
|
||
|
||
def extract_ordinals(ndarray[object] values, freq): | ||
|
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.
don't put this in a separate file, stick in tests/test_tseries.py