Skip to content

fix da.pad example for numpy 1.20 #4865

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 3 commits into from
Feb 7, 2021
Merged
Changes from 1 commit
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
23 changes: 11 additions & 12 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3851,9 +3851,8 @@ def pad(

Notes
-----
By default when ``mode="constant"`` and ``constant_values=None``, integer types will be
promoted to ``float`` and padded with ``np.nan``. To avoid type promotion
specify ``constant_values=np.nan``
For ``mode="constant"`` and ``constant_values=None``, integer types will be
promoted to ``float`` and padded with ``np.nan``.

Examples
--------
Expand All @@ -3880,16 +3879,16 @@ def pad(
* x (x) float64 nan 0.0 1.0 nan
* y (y) int64 10 20 30 40
z (x) float64 nan 100.0 200.0 nan
>>> da.pad(x=1, constant_values=np.nan)

Careful, ``constant_values`` can be coerced to the data type of the array which
may lead to a loss of precision:

>>> da.pad(x=1, constant_values=1.23456789)
<xarray.DataArray (x: 4, y: 4)>
array([[-9223372036854775808, -9223372036854775808, -9223372036854775808,
-9223372036854775808],
[ 0, 1, 2,
3],
[ 10, 11, 12,
13],
[-9223372036854775808, -9223372036854775808, -9223372036854775808,
-9223372036854775808]])
array([[ 1, 1, 1, 1],
[ 0, 1, 2, 3],
[10, 11, 12, 13],
[ 1, 1, 1, 1]])
Coordinates:
* x (x) float64 nan 0.0 1.0 nan
* y (y) int64 10 20 30 40
Expand Down