@@ -1859,8 +1859,10 @@ def reindex_like(
1859
1859
copy : bool = True ,
1860
1860
fill_value = dtypes .NA ,
1861
1861
) -> Self :
1862
- """Conform this object onto the indexes of another object, filling in
1863
- missing values with ``fill_value``. The default fill value is NaN.
1862
+ """
1863
+ Conform this object onto the indexes of another object, for indexes which the
1864
+ objects share. Missing values are filled with ``fill_value``. The default fill
1865
+ value is NaN.
1864
1866
1865
1867
Parameters
1866
1868
----------
@@ -1948,20 +1950,14 @@ def reindex_like(
1948
1950
* x (x) int64 40 30 20 10
1949
1951
* y (y) int64 90 80 70
1950
1952
1951
- Reindexing with the other array having coordinates which the source array doesn't have :
1953
+ Reindexing with the other array having additional coordinates :
1952
1954
1953
- >>> data = np.arange(12).reshape(4, 3)
1954
- >>> da1 = xr.DataArray(
1955
- ... data=data,
1956
- ... dims=["x", "y"],
1957
- ... coords={"x": [10, 20, 30, 40], "y": [70, 80, 90]},
1958
- ... )
1959
- >>> da2 = xr.DataArray(
1955
+ >>> da3 = xr.DataArray(
1960
1956
... data=data,
1961
1957
... dims=["x", "y"],
1962
1958
... coords={"x": [20, 10, 29, 39], "y": [70, 80, 90]},
1963
1959
... )
1964
- >>> da1.reindex_like(da2 )
1960
+ >>> da1.reindex_like(da3 )
1965
1961
<xarray.DataArray (x: 4, y: 3)>
1966
1962
array([[ 3., 4., 5.],
1967
1963
[ 0., 1., 2.],
@@ -1973,7 +1969,7 @@ def reindex_like(
1973
1969
1974
1970
Filling missing values with the previous valid index with respect to the coordinates' value:
1975
1971
1976
- >>> da1.reindex_like(da2 , method="ffill")
1972
+ >>> da1.reindex_like(da3 , method="ffill")
1977
1973
<xarray.DataArray (x: 4, y: 3)>
1978
1974
array([[3, 4, 5],
1979
1975
[0, 1, 2],
@@ -1985,7 +1981,7 @@ def reindex_like(
1985
1981
1986
1982
Filling missing values while tolerating specified error for inexact matches:
1987
1983
1988
- >>> da1.reindex_like(da2 , method="ffill", tolerance=5)
1984
+ >>> da1.reindex_like(da3 , method="ffill", tolerance=5)
1989
1985
<xarray.DataArray (x: 4, y: 3)>
1990
1986
array([[ 3., 4., 5.],
1991
1987
[ 0., 1., 2.],
@@ -1997,7 +1993,7 @@ def reindex_like(
1997
1993
1998
1994
Filling missing values with manually specified values:
1999
1995
2000
- >>> da1.reindex_like(da2 , fill_value=19)
1996
+ >>> da1.reindex_like(da3 , fill_value=19)
2001
1997
<xarray.DataArray (x: 4, y: 3)>
2002
1998
array([[ 3, 4, 5],
2003
1999
[ 0, 1, 2],
@@ -2007,9 +2003,28 @@ def reindex_like(
2007
2003
* x (x) int64 20 10 29 39
2008
2004
* y (y) int64 70 80 90
2009
2005
2006
+ Note that unlike ``broadcast_like``, ``reindex_like`` doesn't create new dimensions:
2007
+
2008
+ >>> da1.sel(x=20)
2009
+ <xarray.DataArray (y: 3)>
2010
+ array([3, 4, 5])
2011
+ Coordinates:
2012
+ x int64 20
2013
+ * y (y) int64 70 80 90
2014
+
2015
+ ...so ``b`` in not added here:
2016
+
2017
+ >>> da1.sel(x=20).reindex_like(da1)
2018
+ <xarray.DataArray (y: 3)>
2019
+ array([3, 4, 5])
2020
+ Coordinates:
2021
+ x int64 20
2022
+ * y (y) int64 70 80 90
2023
+
2010
2024
See Also
2011
2025
--------
2012
2026
DataArray.reindex
2027
+ DataArray.broadcast_like
2013
2028
align
2014
2029
"""
2015
2030
return alignment .reindex_like (
0 commit comments