Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit 5464b10

Browse files
authored
correct doc for DF.var (#694)
1 parent 7a6d9c2 commit 5464b10

2 files changed

Lines changed: 84 additions & 24 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# *****************************************************************************
2+
# Copyright (c) 2020, Intel Corporation All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
#
10+
# Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21+
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23+
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24+
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
# *****************************************************************************
26+
27+
"""
28+
Expected result:
29+
A 0.063333
30+
B 6.333333
31+
C NaN
32+
dtype: float64
33+
"""
34+
35+
import pandas as pd
36+
import numpy as np
37+
from numba import njit
38+
39+
40+
@njit
41+
def dataframe_var():
42+
df = pd.DataFrame({"A": [.2, .0, .6, .2],
43+
"B": [2, 0, 6, 2],
44+
"C": [-1, np.nan, 1, np.inf]})
45+
46+
return df.var()
47+
48+
49+
print(dataframe_var())

‎sdc/datatypes/hpat_pandas_dataframe_functions.py‎

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,8 @@ def check_type(name, df, axis=None, skipna=None, level=None, numeric_only=None,
688688
if not (isinstance(numeric_only, types.Omitted) or numeric_only is None):
689689
ty_checker.raise_exc(numeric_only, 'unsupported', 'numeric_only')
690690

691-
if not (isinstance(ddof, types.Omitted) or ddof == 1):
692-
ty_checker.raise_exc(ddof, 'unsupported', 'ddof')
691+
if not (isinstance(ddof, (types.Omitted, types.Integer)) or ddof == 1):
692+
ty_checker.raise_exc(ddof, 'int', 'ddof')
693693

694694
if not (isinstance(min_count, types.Omitted) or min_count == 0):
695695
ty_checker.raise_exc(min_count, 'unsupported', 'min_count')
@@ -820,32 +820,43 @@ def std_overload(df, axis=None, skipna=None, level=None, ddof=1, numeric_only=No
820820
@sdc_overload_method(DataFrameType, 'var')
821821
def var_overload(df, axis=None, skipna=None, level=None, ddof=1, numeric_only=None):
822822
"""
823-
Pandas DataFrame method :meth:`pandas.DataFrame.var` implementation.
823+
Intel Scalable Dataframe Compiler User Guide
824+
********************************************
824825
825-
.. only:: developer
826+
Pandas API: pandas.DataFrame.var
826827
827-
Test: python -m sdc.runtests -k sdc.tests.test_dataframe.TestDataFrame.test_var*
828+
Limitations
829+
-----------
830+
Parameters ``axis``, ``level`` and ``numeric_only`` are unsupported.
828831
829-
Parameters
830-
-----------
831-
df: :class:`pandas.DataFrame`
832-
input arg
833-
axis:
834-
*unsupported*
835-
skipna:
836-
*unsupported*
837-
level:
838-
*unsupported*
839-
ddof:
840-
*unsupported*
841-
numeric_only:
842-
*unsupported*
832+
Examples
833+
--------
834+
.. literalinclude:: ../../../examples/dataframe/dataframe_var.py
835+
:language: python
836+
:lines: 35-
837+
:caption: Return unbiased variance over requested axis.
838+
:name: ex_dataframe_var
843839
844-
Returns
845-
-------
846-
:obj:`pandas.Series` or `pandas.DataFrame`
847-
return sample standard deviation over requested axis.
848-
"""
840+
.. command-output:: python ./dataframe/dataframe_var.py
841+
:cwd: ../../../examples
842+
843+
.. seealso::
844+
:ref:`Series.std <pandas.Series.std>`
845+
Returns sample standard deviation over Series.
846+
:ref:`Series.var<pandas.Series.var>`
847+
Returns unbiased variance over Series.
848+
:ref:`DataFrame.std <pandas.DataFrame.std>`
849+
Returns sample standard deviation over DataFrame.
850+
851+
Intel Scalable Dataframe Compiler Developer Guide
852+
*************************************************
853+
854+
Pandas DataFrame method :meth:`pandas.DataFrame.var` implementation.
855+
856+
.. only:: developer
857+
858+
Test: python -m sdc.runtests -k sdc.tests.test_dataframe.TestDataFrame.test_var*
859+
"""
849860

850861
name = 'var'
851862

0 commit comments

Comments
 (0)