This repository was archived by the owner on Feb 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Impl Series.skew() #813
Merged
AlexanderKalistratov
merged 16 commits into
IntelPython:master
from
Rubtsowa:series_skew
Apr 27, 2020
Merged
Impl Series.skew() #813
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a109d42
Impl Series.skew()
Rubtsowa 61d93ab
fix problem with PEP8
Rubtsowa cf2b556
change impl
Rubtsowa c4e85fa
not copy data
Rubtsowa b7948d4
add functions for skew in numpy_like
Rubtsowa 5ce5343
change functions in numpy_like, extension unittest, add perf test
Rubtsowa 1f49c89
change perf test & change functions in numpy_like
Rubtsowa 6bfca08
change functions in numpy_like
Rubtsowa 9888b7b
not use global_input_data_integer in tests
Rubtsowa 8089aa0
change perf test
Rubtsowa fdd2b7e
Merge branch 'master' of https://github.com/IntelPython/hpat into ser…
Rubtsowa 75b007d
putting the formula in a separate file
Rubtsowa a39a951
rename file
Rubtsowa df54e1b
add statics.py
Rubtsowa acf9943
rename file
Rubtsowa 73299c5
delete statics
Rubtsowa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ***************************************************************************** | ||
# Copyright (c) 2020, Intel Corporation All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are met: | ||
# | ||
# Redistributions of source code must retain the above copyright notice, | ||
# this list of conditions and the following disclaimer. | ||
# | ||
# Redistributions in binary form must reproduce the above copyright notice, | ||
# this list of conditions and the following disclaimer in the documentation | ||
# and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# ***************************************************************************** | ||
|
||
import pandas as pd | ||
import numpy as np | ||
from numba import njit | ||
|
||
|
||
@njit | ||
def series_skew(): | ||
s = pd.Series([np.nan, -2., 3., 5.0]) | ||
|
||
return s.skew() # Expect -1.1520696383139375 | ||
|
||
|
||
print(series_skew()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5725,3 +5725,89 @@ def sdc_pandas_series_groupby_impl(self, by=None, axis=0, level=None, as_index=T | |
return init_series_groupby(self, by, grouped, sort) | ||
|
||
return sdc_pandas_series_groupby_impl | ||
|
||
|
||
@sdc_overload_method(SeriesType, 'skew') | ||
def sdc_pandas_series_skew(self, axis=None, skipna=None, level=None, numeric_only=None): | ||
""" | ||
Intel Scalable Dataframe Compiler User Guide | ||
******************************************** | ||
|
||
Pandas API: pandas.Series.skew | ||
|
||
Limitations | ||
----------- | ||
- Parameters ``level`` and ``numeric_only`` are supported only with default value ``None``. | ||
|
||
Examples | ||
-------- | ||
.. literalinclude:: ../../../examples/series/series_skew.py | ||
:language: python | ||
:lines: 27- | ||
:caption: Unbiased rolling skewness. | ||
:name: ex_series_skew | ||
|
||
.. command-output:: python ./series/series_skew.py | ||
:cwd: ../../../examples | ||
|
||
Intel Scalable Dataframe Compiler Developer Guide | ||
************************************************* | ||
Pandas Series method :meth:`pandas.Series.skew` implementation. | ||
|
||
.. only:: developer | ||
Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_skew* | ||
""" | ||
_func_name = 'Method Series.skew()' | ||
|
||
ty_checker = TypeChecker(_func_name) | ||
ty_checker.check(self, SeriesType) | ||
|
||
if not isinstance(axis, (types.Integer, types.NoneType, types.Omitted)) and axis is not None: | ||
ty_checker.raise_exc(axis, 'int64', 'axis') | ||
|
||
if not isinstance(skipna, (types.Boolean, types.NoneType, types.Omitted)) and skipna is not None: | ||
ty_checker.raise_exc(skipna, 'bool', 'skipna') | ||
|
||
if not isinstance(level, (types.Omitted, types.NoneType)) and level is not None: | ||
ty_checker.raise_exc(level, 'None', 'level') | ||
|
||
if not isinstance(numeric_only, (types.Omitted, types.NoneType)) and numeric_only is not None: | ||
ty_checker.raise_exc(numeric_only, 'None', 'numeric_only') | ||
|
||
def sdc_pandas_series_skew_impl(self, axis=None, skipna=None, level=None, numeric_only=None): | ||
if axis != 0 and axis is not None: | ||
raise ValueError('Parameter axis must be only 0 or None.') | ||
|
||
if skipna is None: | ||
_skipna = True | ||
else: | ||
_skipna = skipna | ||
|
||
infinite_mask = numpy.isfinite(self._data) | ||
len_val = len(infinite_mask) | ||
data = self._data[infinite_mask] | ||
|
||
nfinite = len(data) | ||
|
||
if not _skipna and nfinite < len_val: | ||
return numpy.nan | ||
else: | ||
_sum = 0 | ||
square_sum = 0 | ||
cube_sum = 0 | ||
|
||
for i in numba.prange(nfinite): | ||
_sum += data[i] | ||
square_sum += data[i] ** 2 | ||
cube_sum += data[i] ** 3 | ||
|
||
n = nfinite | ||
m2 = (square_sum - _sum * _sum / n) / n | ||
m3 = (cube_sum - 3. * _sum * square_sum / n + 2. * _sum * _sum * _sum / n / n) / n | ||
res = numpy.nan if m2 == 0 else m3 / m2 ** 1.5 | ||
|
||
if (n > 2) & (m2 > 0): | ||
res = numpy.sqrt((n - 1.) * n) / (n - 2.) * m3 / m2 ** 1.5 | ||
|
||
return res | ||
|
||
return sdc_pandas_series_skew_impl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
No. that's kills performance and scalability