-
Notifications
You must be signed in to change notification settings - Fork 62
Implement series.cumsum() in new style #192
Conversation
hpat/hiframes/pd_series_ext.py
Outdated
install_array_method(fname, generic_expand_cumulative_series) | ||
|
||
# TODO: add itemsize, strides, etc. when removed from Pandas | ||
_not_series_array_attrs = ['flat', 'ctypes', 'itemset', 'reshape', 'sort', 'flatten'] | ||
|
||
# Array attributes which overlap Series attributes | ||
_excluded_array_attrs = ['cumsum'] |
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.
did you try just add cumsum
into _not_series_array_attrs
array?
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.
Yes I did. In this case the method isn't skipped because condition attr not in _not_series_array_attrs
is True
due to attr = 'resolve_cumsum'
but not just 'cumsum'
. It looks like an issue, because now this condition is always True
. Perhaps attr.replace('resolve_', '')
might be useful in this case.
hpat/hiframes/pd_series_ext.py
Outdated
# use ArrayAttribute for attributes not defined in SeriesAttribute | ||
for attr, func in numba.typing.arraydecl.ArrayAttribute.__dict__.items(): | ||
if (attr.startswith('resolve_') | ||
and attr not in SeriesAttribute.__dict__ | ||
and attr not in _not_series_array_attrs): | ||
and attr not in _not_series_array_attrs | ||
and attr.replace('resolve_', '') not in _excluded_array_attrs): |
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.
Could you show all function names registered by setattr(SeriesAttribute, attr, func)
?
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.
print(attr.replace('resolve_', ''))
printed
dtype
, itemsize
, shape
, strides
, ndim
, size
, flat
, ctypes
, flags
, T
, real
, imag
, transpose
, item
, itemset
, nonzero
, reshape
, sort
, view
, ravel
, flatten
, prod
, sum
, mean
, var
, std
, argmin
, argmax
9d73d3d
to
c3baf97
Compare
Please resolve conflicts |
4e8e09a
to
6b74735
Compare
axis: :obj:`int`, :obj:`str` | ||
Axis along which the operation acts | ||
0/None - row-wise operation | ||
1 - column-wise operation |
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.
it looks like description is not quite accurate. this parameter can be integer or string (as described in line 1507).
Please add string variant. I mean something like 0 or ‘index’, 1 or ‘columns’
Returns | ||
------- | ||
:obj:`pandas.Series` | ||
returns :obj:`pandas.Series` object |
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.
it might return scalar but I don't know cases for this
_func_name = 'Method cumsum().' | ||
|
||
if not isinstance(self, SeriesType): | ||
raise TypingError('{} The object must be a pandas.series. Given self: {}'.format(_func_name, self)) |
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.
Given self
-> Given
raise TypingError('{} The object must be a pandas.series. Given self: {}'.format(_func_name, self)) | ||
|
||
if not isinstance(self.dtype, types.Number): | ||
raise TypingError('{} The object must be a number. Given self.dtype: {}'.format(_func_name, self.dtype)) |
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.
see #216 (comment)
also, message Given self.dtype
means nothing for user. Please keep messages understandable as much as possible
def hpat_pandas_series_cumsum_impl(self, axis=None, skipna=True): | ||
if skipna: | ||
# nampy.nancumsum replaces NANs with 0, series.cumsum does not, so replace back 0 with NANs | ||
data = numpy.nancumsum(self._data) |
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.
please use something like local_data
instead data
to avoid intersection with class variables and types
hpat/tests/test_series.py
Outdated
pyfunc = test_impl | ||
cfunc = hpat.jit(pyfunc) | ||
|
||
series = pd.Series([1.0, np.nan, 9.0, -1.0, 7.0]) |
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.
Please see #217 (comment)
d0b90c9
to
49be153
Compare
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.
In case of input data, it might be too early to implement this.
I would be better to implement it for all tests (at least in Series) at one time.
Anyway, please follow data type hierarchy if you would like to start this in this PR
hpat/tests/test_series.py
Outdated
[1.0, np.nan, -1.0, 0.0, 5e-324], | ||
[np.nan, np.inf, np.NINF, np.NZERO] | ||
] | ||
FLOAT_EXAMPLE, *_ = FLOAT_EXAMPLES |
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.
on need this variable. FLOAT_EXAMPLES[0] instead
hpat/tests/test_series.py
Outdated
@@ -34,6 +37,28 @@ | |||
), | |||
]] | |||
|
|||
FLOAT_EXAMPLES = [ |
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.
FLOAT_EXAMPLES = [ | |
test_global_input_data_float64 = [ |
hpat/tests/test_series.py
Outdated
] | ||
FLOAT_EXAMPLE, *_ = FLOAT_EXAMPLES | ||
INT_EXAMPLE = [1, -1, 0, 18446744073709551615] | ||
NUM_EXAMPLES = [INT_EXAMPLE] + FLOAT_EXAMPLES |
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.
NUM_EXAMPLES = [INT_EXAMPLE] + FLOAT_EXAMPLES | |
test_global_input_data_numeric = [INT_EXAMPLE] + FLOAT_EXAMPLES |
hpat/tests/test_series.py
Outdated
[np.nan, np.inf, np.NINF, np.NZERO] | ||
] | ||
FLOAT_EXAMPLE, *_ = FLOAT_EXAMPLES | ||
INT_EXAMPLE = [1, -1, 0, 18446744073709551615] |
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.
INT_EXAMPLE = [1, -1, 0, 18446744073709551615] | |
test_global_input_data_integer64 = [1, -1, 0, 18446744073709551615] |
hpat/tests/test_series.py
Outdated
|
||
STR_EXAMPLES = [ | ||
['', 'a' 'aa', 'aaa', 'b', 'aab', 'ab', 'abababab'], | ||
UNICODE_EXAMPLES |
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 include it here
hpat/tests/test_series.py
Outdated
INT_EXAMPLE = [1, -1, 0, 18446744073709551615] | ||
NUM_EXAMPLES = [INT_EXAMPLE] + FLOAT_EXAMPLES | ||
|
||
UNICODE_EXAMPLES = [ |
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.
UNICODE_EXAMPLES = [ | |
test_global_input_data_unicode_kind4 = [ |
hpat/tests/test_series.py
Outdated
] | ||
|
||
min_int64 = -9223372036854775808 | ||
max_int64 = 9223372036854775807 |
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.
sys.intmax
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.
@densmirn Use numba.targets.builtins.get_type_max_value for this
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.
Added.
8dfe505
to
c7e9319
Compare
@shssf, @kozlov-alexey could you take the next round to review the PR? |
No description provided.