Skip to content

Commit 3156fe4

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.DataFrame.var (#58568)
* DOC: add PR01,RT03,SA01 for pandas.DataFrame.var * DOC: remove PR01,RT03,SA01 for pandas.DataFrame.var * DOC: add more examples
1 parent 4a4c076 commit 3156fe4

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7979
-i "pandas.DataFrame.sum RT03" \
8080
-i "pandas.DataFrame.swaplevel SA01" \
8181
-i "pandas.DataFrame.to_markdown SA01" \
82-
-i "pandas.DataFrame.var PR01,RT03,SA01" \
8382
-i "pandas.Grouper PR02" \
8483
-i "pandas.Index PR07" \
8584
-i "pandas.Index.join PR07,RT03,SA01" \

pandas/core/frame.py

+69-1
Original file line numberDiff line numberDiff line change
@@ -12065,7 +12065,6 @@ def var(
1206512065
) -> Series | Any: ...
1206612066

1206712067
@deprecate_nonkeyword_arguments(version="3.0", allowed_args=["self"], name="var")
12068-
@doc(make_doc("var", ndim=2))
1206912068
def var(
1207012069
self,
1207112070
axis: Axis | None = 0,
@@ -12074,6 +12073,75 @@ def var(
1207412073
numeric_only: bool = False,
1207512074
**kwargs,
1207612075
) -> Series | Any:
12076+
"""
12077+
Return unbiased variance over requested axis.
12078+
12079+
Normalized by N-1 by default. This can be changed using the ddof argument.
12080+
12081+
Parameters
12082+
----------
12083+
axis : {index (0), columns (1)}
12084+
For `Series` this parameter is unused and defaults to 0.
12085+
12086+
.. warning::
12087+
12088+
The behavior of DataFrame.var with ``axis=None`` is deprecated,
12089+
in a future version this will reduce over both axes and return a scalar
12090+
To retain the old behavior, pass axis=0 (or do not pass axis).
12091+
12092+
skipna : bool, default True
12093+
Exclude NA/null values. If an entire row/column is NA, the result
12094+
will be NA.
12095+
ddof : int, default 1
12096+
Delta Degrees of Freedom. The divisor used in calculations is N - ddof,
12097+
where N represents the number of elements.
12098+
numeric_only : bool, default False
12099+
Include only float, int, boolean columns. Not implemented for Series.
12100+
**kwargs :
12101+
Additional keywords passed.
12102+
12103+
Returns
12104+
-------
12105+
Series or scalaer
12106+
Unbiased variance over requested axis.
12107+
12108+
See Also
12109+
--------
12110+
numpy.var : Equivalent function in NumPy.
12111+
Series.var : Return unbiased variance over Series values.
12112+
Series.std : Return standard deviation over Series values.
12113+
DataFrame.std : Return standard deviation of the values over
12114+
the requested axis.
12115+
12116+
Examples
12117+
--------
12118+
>>> df = pd.DataFrame(
12119+
... {
12120+
... "person_id": [0, 1, 2, 3],
12121+
... "age": [21, 25, 62, 43],
12122+
... "height": [1.61, 1.87, 1.49, 2.01],
12123+
... }
12124+
... ).set_index("person_id")
12125+
>>> df
12126+
age height
12127+
person_id
12128+
0 21 1.61
12129+
1 25 1.87
12130+
2 62 1.49
12131+
3 43 2.01
12132+
12133+
>>> df.var()
12134+
age 352.916667
12135+
height 0.056367
12136+
dtype: float64
12137+
12138+
Alternatively, ``ddof=0`` can be set to normalize by N instead of N-1:
12139+
12140+
>>> df.var(ddof=0)
12141+
age 264.687500
12142+
height 0.042275
12143+
dtype: float64
12144+
"""
1207712145
result = super().var(
1207812146
axis=axis, skipna=skipna, ddof=ddof, numeric_only=numeric_only, **kwargs
1207912147
)

0 commit comments

Comments
 (0)