-
Notifications
You must be signed in to change notification settings - Fork 62
Implement Series.mean() in new style #219
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1388,6 +1388,67 @@ def hpat_pandas_series_max_impl(self, axis=None, skipna=True, level=None, numeri | |||||
| return hpat_pandas_series_max_impl | ||||||
|
|
||||||
|
|
||||||
| @overload_method(SeriesType, 'mean') | ||||||
| def hpat_pandas_series_mean(self, axis=None, skipna=None, level=None, numeric_only=None): | ||||||
|
Contributor
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.
Suggested change
|
||||||
| """ | ||||||
| Pandas Series method :meth:`pandas.Series.mean` implementation. | ||||||
|
|
||||||
| .. only:: developer | ||||||
|
|
||||||
| Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_mean | ||||||
|
|
||||||
| Parameters | ||||||
| ----------- | ||||||
| axis: {index (0)} | ||||||
| Axis for the function to be applied on. | ||||||
| *unsupported* | ||||||
| skipna: :obj:`bool`, default True | ||||||
| Exclude NA/null values when computing the result. | ||||||
| level: :obj:`int` or level name, default None | ||||||
| If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar. | ||||||
| *unsupported* | ||||||
| numeric_only: :obj:`bool`, default None | ||||||
| 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: | ||||||
| Return the mean of the values for the requested axis. | ||||||
| """ | ||||||
|
|
||||||
| _func_name = 'Method mean().' | ||||||
|
|
||||||
| 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): | ||||||
| raise TypingError('{} Currently function supports only numeric values. Given data type: {}'.format(_func_name, self.data.dtype)) | ||||||
|
|
||||||
| if not isinstance(skipna, (types.Omitted, types.Boolean)) and skipna is not None: | ||||||
| raise TypingError( | ||||||
| '{} The parameter must be a boolean type. Given type skipna: {}'.format(_func_name, skipna)) | ||||||
|
|
||||||
| if not (isinstance(axis, types.Omitted) or axis is None) \ | ||||||
| or not (isinstance(level, types.Omitted) or level is None) \ | ||||||
| or not (isinstance(numeric_only, types.Omitted) or numeric_only is None): | ||||||
| raise TypingError( | ||||||
| '{} Unsupported parameters. Given axis: {}, level: {}, numeric_only: {}'.format(_func_name, axis, level, | ||||||
| numeric_only)) | ||||||
|
|
||||||
| def hpat_pandas_series_mean_impl(self, axis=None, skipna=None, level=None, numeric_only=None): | ||||||
|
Contributor
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.
Suggested change
Contributor
Author
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. @shssf could you please explain in this issue #233 for me and all why we should replace Pandas signature
Contributor
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. @PokhodenkoSA I would refer to Pandas sources. Please follow signature defined there. Documentation might have a bugs as a regular code. Anyway, by the algo you implemented it is True despite of the fact it None |
||||||
| if skipna is None: | ||||||
| skipna = True | ||||||
|
|
||||||
| if skipna: | ||||||
| return numpy.nanmean(self._data) | ||||||
|
|
||||||
| return self._data.mean() | ||||||
|
|
||||||
| return hpat_pandas_series_mean_impl | ||||||
|
|
||||||
|
|
||||||
| @overload_method(SeriesType, 'mod') | ||||||
| def hpat_pandas_series_mod(self, other, level=None, fill_value=None, axis=0): | ||||||
| """ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1228,13 +1228,59 @@ def test_impl(S): | |
| S = pd.Series(['aa', 'bb', np.nan]) | ||
| self.assertEqual(hpat_func(S), test_impl(S)) | ||
|
|
||
| def test_series_mean1(self): | ||
| def test_series_mean(self): | ||
| def test_impl(S): | ||
| return S.mean() | ||
| hpat_func = hpat.jit(test_impl) | ||
|
|
||
| S = pd.Series([np.nan, 2., 3.]) | ||
| self.assertEqual(hpat_func(S), test_impl(S)) | ||
| data_samples = [ | ||
| [6, 6, 2, 1, 3, 3, 2, 1, 2], | ||
| [1.1, 0.3, 2.1, 1, 3, 0.3, 2.1, 1.1, 2.2], | ||
| [6, 6.1, 2.2, 1, 3, 3, 2.2, 1, 2], | ||
| [6, 6, np.nan, 2, np.nan, 1, 3, 3, np.inf, 2, 1, 2, np.inf], | ||
| [1.1, 0.3, np.nan, 1.0, np.inf, 0.3, 2.1, np.nan, 2.2, np.inf], | ||
| [1.1, 0.3, np.nan, 1, np.inf, 0, 1.1, np.nan, 2.2, np.inf, 2, 2], | ||
| [np.nan, np.nan, np.nan], | ||
| [np.nan, np.nan, np.inf], | ||
| ] | ||
|
|
||
| for data in data_samples: | ||
| with self.subTest(data=data): | ||
| S = pd.Series(data) | ||
| actual = hpat_func(S) | ||
| expected = test_impl(S) | ||
| if np.isnan(actual) or np.isnan(expected): | ||
| self.assertEqual(np.isnan(actual), np.isnan(expected)) | ||
| else: | ||
| self.assertEqual(actual, expected) | ||
|
|
||
| @unittest.skipIf(hpat.config.config_pipeline_hpat_default, "Series.mean() any parameters unsupported") | ||
|
Contributor
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. if
Contributor
Author
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 is correct. This test does not work with HPAT pipeline. |
||
| def test_series_mean_skipna(self): | ||
| def test_impl(S, skipna): | ||
| return S.mean(skipna=skipna) | ||
| hpat_func = hpat.jit(test_impl) | ||
|
|
||
| data_samples = [ | ||
| [6, 6, 2, 1, 3, 3, 2, 1, 2], | ||
| [1.1, 0.3, 2.1, 1, 3, 0.3, 2.1, 1.1, 2.2], | ||
| [6, 6.1, 2.2, 1, 3, 3, 2.2, 1, 2], | ||
| [6, 6, np.nan, 2, np.nan, 1, 3, 3, np.inf, 2, 1, 2, np.inf], | ||
| [1.1, 0.3, np.nan, 1.0, np.inf, 0.3, 2.1, np.nan, 2.2, np.inf], | ||
| [1.1, 0.3, np.nan, 1, np.inf, 0, 1.1, np.nan, 2.2, np.inf, 2, 2], | ||
| [np.nan, np.nan, np.nan], | ||
| [np.nan, np.nan, np.inf], | ||
| ] | ||
|
|
||
| for skipna in [True, False]: | ||
| for data in data_samples: | ||
| S = pd.Series(data) | ||
| actual = hpat_func(S, skipna) | ||
| expected = test_impl(S, skipna) | ||
| if np.isnan(actual) or np.isnan(expected): | ||
| self.assertEqual(np.isnan(actual), np.isnan(expected)) | ||
| else: | ||
| self.assertEqual(actual, expected) | ||
|
|
||
|
|
||
| def test_series_var1(self): | ||
| def test_impl(S): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.