Skip to content

DOC: Fix examples in pandas/core/ops/ #33176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pytest -q --doctest-modules pandas/core/indexes/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests reshaping functions' ; echo $MSG
MSG='Doctests ops' ; echo $MSG
pytest -q --doctest-modules pandas/core/ops/
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests reshape' ; echo $MSG
pytest -q --doctest-modules pandas/core/reshape/
RET=$(($RET + $?)) ; echo $MSG "DONE"

Expand Down
9 changes: 6 additions & 3 deletions pandas/core/ops/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def fill_zeros(result, x, y):

def mask_zero_div_zero(x, y, result):
"""
Set results of 0 / 0 or 0 // 0 to np.nan, regardless of the dtypes
Set results of 0 // 0 to np.nan, regardless of the dtypes
of the numerator or the denominator.

Parameters
Expand All @@ -83,13 +83,16 @@ def mask_zero_div_zero(x, y, result):

Returns
-------
filled_result : ndarray
ndarray
The filled result.

Examples
--------
>>> x = np.array([1, 0, -1], dtype=np.int64)
>>> x
array([ 1, 0, -1])
>>> y = 0 # int 0; numpy behavior is different with float
>>> result = x / y
>>> result = x // y
Copy link
Member

@simonjayhawkins simonjayhawkins Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elif op is operator.floordiv:
# Note: no need to do this for truediv; in py3 numpy behaves the way
# we want.
result = mask_zero_div_zero(left, right, result)

maybe update the docstring to reflect this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins I'm not sure I understand what to update, can you be more specific?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def mask_zero_div_zero(x, y, result):
"""
Set results of 0 / 0 or 0 // 0 to np.nan, regardless of the dtypes
of the numerator or the denominator.

>>> result # raw numpy result does not fill division by zero
array([0, 0, 0])
>>> mask_zero_div_zero(x, y, result)
Expand Down