Fix: docs: fix DataArray.pad constant_values default documentation
Fixed pydata/xarray#11373 — 2 line bug-fix.

The Bug
Repo: pydata/xarray Issue: #11373 Status: PR-submitted PR: https://github.com/pydata/xarray/pull/11447
Description: docs: fix DataArray.pad constant_values default documentation
Fix scope: 2 lines changed in xarray/core/dataarray.py
Root Cause
The edge case in class DataArray( at xarray/core/dataarray.py causes incorrect behavior when
a specific input condition is met. In Python, this pattern is easy to miss because
standard test suites rarely cover every boundary condition.
The fix is a surgical change — it addresses exactly the failing condition without refactoring surrounding code. This minimizes the risk of introducing new bugs.
Impact: The bug affects users who hit the specific edge case. For xarray, this means 2 lines fixes a scenario that could cause incorrect output, crashes, or silent data corruption depending on the code path.
The Fix
This is a surgical fix — every line is deliberate and scoped to exactly the problem.
@@ -5912,7 +5912,7 @@ class DataArray(
(stat_length,) or int is a shortcut for before = after = statistic
length for all axes.
Default is ``None``, to use the entire axis.
- constant_values : scalar, tuple or mapping of Hashable to tuple, default: 0
+ constant_values : scalar, tuple or mapping of Hashable to tuple, default: None
Used in 'constant'. The values to set the padded values for each
axis.
``{dim_1: (before_1, after_1), ... dim_N: (before_N, after_N)}`` unique
@@ -5921,7 +5921,7 @@ class DataArray(
dimension.
``(constant,)`` or ``constant`` is a shortcut for ``before = after = constant`` for
all dimensions.
- Default is 0.
+ Default is ``None``, pads with ``np.nan``.
end_values : scalar, tuple or mapping of Hashable to tuple, default: 0
Used in 'linear_ramp'. The values used for the ending value of the
linear_ramp and that will form the edge of the padded array.
Pattern & Takeaways
Pattern: Edge case in class DataArray( — the Python code path was not tested
with the specific input that triggers the failure. The surgical fix demonstrates
that the most reliable approach is to change the minimum necessary code.
Key insight: The most predictable bugs are edge cases at input boundaries. Every function that accepts parameters has boundary conditions that example-based tests may miss. Code review should focus on: (1) What happens with empty/null input? (2) What happens at iteration boundaries? (3) What happens with unexpected types?
Transfer Potential
Varies — edge case fixes are repo-specific in detail but universal in pattern. The minimal-change principle and boundary-condition thinking transfer to any codebase. Reading this post helps recognize similar patterns in your own projects.
Auto-generated from PR #11373. View all patches on GitHub.