-
Notifications
You must be signed in to change notification settings - Fork 62
Implement series.var() in new style #220
Changes from all commits
942d0fd
6c27327
f783e97
a1d287a
83d9300
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 |
---|---|---|
|
@@ -256,6 +256,86 @@ def hpat_pandas_series_values_impl(self): | |
return hpat_pandas_series_values_impl | ||
|
||
|
||
@overload_method(SeriesType, 'var') | ||
def hpat_pandas_series_var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None): | ||
""" | ||
Pandas Series method :meth:`pandas.Series.var` implementation. | ||
|
||
.. only:: developer | ||
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_var | ||
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_var_unboxing | ||
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_var_str | ||
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_var_unsupported_params | ||
|
||
Parameters | ||
---------- | ||
self: :obj:`pandas.Series` | ||
input series | ||
axis: :obj:`int`, :obj:`str` | ||
Axis along which the operation acts | ||
0/None/'index' - row-wise operation | ||
1/'columns' - column-wise operation | ||
*unsupported* | ||
skipna: :obj:`bool` | ||
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. I suspect skipna=True 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. By default |
||
exclude NA/null values | ||
level: :obj:`int`, :obj:`str` | ||
If the axis is a MultiIndex (hierarchical), | ||
count along a particular level, collapsing into a scalar | ||
*unsupported* | ||
ddof: :obj:`int` | ||
Delta Degrees of Freedom. | ||
The divisor used in calculations is N - ddof, | ||
where N represents the number of elements. | ||
numeric_only: :obj:`bool` | ||
Include only float, int, boolean columns. | ||
If None, will attempt to use everything, then use only numeric data. | ||
Not implemented for Series. | ||
*unsupported* | ||
|
||
Returns | ||
------- | ||
:obj:`scalar` | ||
returns :obj:`scalar` | ||
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. It can return scalar or Series 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. I'm not sure we have to add |
||
""" | ||
|
||
_func_name = 'Method var().' | ||
|
||
if not isinstance(self, SeriesType): | ||
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self)) | ||
|
||
if not isinstance(self.data.dtype, types.Number): | ||
msg = '{} The object must be a number. Given self.data.dtype: {}' | ||
raise TypingError(msg.format(_func_name, self.data.dtype)) | ||
|
||
if not isinstance(skipna, (types.Omitted, types.Boolean, types.NoneType)) and skipna is not None: | ||
raise TypingError('{} The object must be a boolean. Given skipna: {}'.format(_func_name, skipna)) | ||
|
||
if not isinstance(ddof, (types.Omitted, int, types.Integer)): | ||
raise TypingError('{} The object must be an integer. Given ddof: {}'.format(_func_name, ddof)) | ||
|
||
for name, arg in [('axis', axis), ('level', level), ('numeric_only', numeric_only)]: | ||
if not isinstance(arg, (types.Omitted, types.NoneType)) and arg is not None: | ||
raise TypingError('{} Unsupported parameters. Given {}: {}'.format(_func_name, name, arg)) | ||
|
||
def hpat_pandas_series_var_impl(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None): | ||
if skipna is None: | ||
skipna = True | ||
|
||
if skipna: | ||
valuable_length = len(self._data) - numpy.sum(numpy.isnan(self._data)) | ||
if valuable_length <= ddof: | ||
return numpy.nan | ||
|
||
return numpy.nanvar(self._data) * valuable_length / (valuable_length - ddof) | ||
|
||
if len(self._data) <= ddof: | ||
return numpy.nan | ||
|
||
return self._data.var() * len(self._data) / (len(self._data) - ddof) | ||
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. I don't believe numpy has no such functionality 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. Numpy implementation has |
||
|
||
return hpat_pandas_series_var_impl | ||
|
||
|
||
@overload_attribute(SeriesType, 'index') | ||
def hpat_pandas_series_index(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.
skipna=True?
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.
By default
skipna=None
in Pandas interface.