{"id":1145,"library":"xarray","title":"Xarray","description":"Xarray (pronounced 'ex-array') is an open-source Python package that simplifies working with labelled multi-dimensional arrays and datasets. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, enabling a more intuitive and less error-prone experience for scientific computing and data analysis, particularly for earth sciences. As of February 2026, the current version is 2026.2.0. Xarray maintains a regular release cadence, with minor versions typically released monthly or bi-monthly.","status":"active","version":"2026.2.0","language":"python","source_language":"en","source_url":"https://github.com/pydata/xarray","tags":["data analysis","scientific computing","netcdf","zarr","labeled arrays","multidimensional","geospatial"],"install":[{"cmd":"pip install xarray","lang":"bash","label":"Core installation"},{"cmd":"pip install \"xarray[complete]\"","lang":"bash","label":"Full installation with all optional dependencies"}],"dependencies":[{"reason":"Core requirement","package":"python","min_version":"3.11"},{"reason":"Required for core array operations","package":"numpy","min_version":"1.26"},{"reason":"Required for core data structures and compatibility","package":"pandas","min_version":"2.2"},{"reason":"Required for dependency version management","package":"packaging","min_version":"24.1"},{"reason":"Optional, for parallel and out-of-core computing","package":"dask","optional":true},{"reason":"Optional, recommended for reading and writing NetCDF files","package":"netCDF4","optional":true},{"reason":"Optional, for accelerating NaN-skipping and rolling window aggregations","package":"bottleneck","optional":true},{"reason":"Optional, for chunked, compressed, N-dimensional arrays","package":"zarr","optional":true},{"reason":"Optional, for plotting capabilities","package":"matplotlib","optional":true}],"imports":[{"symbol":"DataArray","correct":"import xarray as xr; da = xr.DataArray(...)"},{"symbol":"Dataset","correct":"import xarray as xr; ds = xr.Dataset(...)"},{"note":"The library was renamed from 'xray' to 'xarray' in January 2016. The 'xray' module no longer exists.","wrong":"import xray as xr","symbol":"xray","correct":"import xarray as xr"}],"quickstart":{"code":"import xarray as xr\nimport numpy as np\nimport pandas as pd\n\n# Create a DataArray\ndata_array = xr.DataArray(\n    np.random.rand(2, 3),\n    coords={\"x\": [10, 20], \"y\": [\"a\", \"b\", \"c\"]},\n    dims=(\"x\", \"y\"),\n    name=\"random_data\"\n)\n\n# Create a Dataset with two DataArrays sharing coordinates\ntemp = xr.DataArray(\n    25 + 10 * np.random.randn(2, 3, 4),\n    coords={\n        \"time\": pd.to_datetime([\"2026-01-01\", \"2026-01-02\"]),\n        \"lat\": [40, 50],\n        \"lon\": [100, 110, 120, 130]\n    },\n    dims=(\"time\", \"lat\", \"lon\"),\n    name=\"temperature\",\n    attrs={\"units\": \"Celsius\", \"long_name\": \"Air Temperature\"}\n)\n\nprecip = xr.DataArray(\n    5 * np.random.rand(2, 3, 4),\n    coords=temp.coords, # Share coordinates from temp\n    dims=temp.dims,\n    name=\"precipitation\",\n    attrs={\"units\": \"mm\", \"long_name\": \"Precipitation Rate\"}\n)\n\ndataset = xr.Dataset({\"temp\": temp, \"precip\": precip})\n\n# Perform a simple operation (e.g., mean over 'time' dimension)\nmean_temp = dataset[\"temp\"].mean(dim=\"time\")\n\nprint(\"DataArray:\\n\", data_array)\nprint(\"\\nDataset:\\n\", dataset)\nprint(\"\\nMean temperature over time:\\n\", mean_temp)","lang":"python","description":"This quickstart demonstrates the creation of a basic `DataArray` and a `Dataset`, including dimension names, coordinates, and attributes. It then shows how to perform a simple aggregation (mean) on a variable within the `Dataset` along a specified dimension."},"warnings":[{"fix":"Review code that relies on attributes being dropped by default. If the old behavior is desired, explicitly set `keep_attrs=False` or manually manage attributes.","message":"Default attribute preservation behavior changed in `xarray` v2025.11.0. All operations now preserve attributes by default. Previously, attributes were dropped unless `keep_attrs=True` was explicitly set. Binary operations now combine attributes using `drop_conflicts` instead of keeping only the left operand's attributes.","severity":"breaking","affected_versions":">=2025.11.0"},{"fix":"Explicitly convert the `DataArray` to a NumPy array using `.values` before applying the NumPy ufunc (e.g., `np.add.reduce(da.values)`).","message":"Direct application of certain NumPy ufuncs to `xarray.DataArray` objects may now raise `NotImplementedError` due to the `__array_ufunc__` protocol. This affects ufuncs that previously implicitly converted `DataArray` to a NumPy array.","severity":"breaking","affected_versions":">=0.10.2"},{"fix":"If only data identity is required, compare the underlying data (`.values` or by casting to `pandas.DataFrame`). Adjust identity checks if index differences are now considered relevant.","message":"The behavior of `Dataset.identical()`, `DataArray.identical()`, and `testing.assert_identical()` changed to include comparison of indexes. Two objects with identical data but different indexes will no longer be considered identical.","severity":"breaking","affected_versions":">=2026.2.0"},{"fix":"Ensure that the length of each coordinate provided for a dimension precisely matches the actual size of that dimension in the input data or dataset being constructed. For example, if data has shape `(3, 2)` for dimensions `('lat', 'lon')`, then `coords['lat']` must have length `3` and `coords['lon']` must have length `2`.","message":"A `ValueError` is raised when constructing an `xarray.DataArray` or `Dataset` if the size of a dimension in the input data does not match the length of its corresponding coordinate array.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"To resolve this, install the HDF5 development package on your Alpine system (e.g., `apk add hdf5-dev`) before attempting to install 'netCDF4' or xarray with netCDF4 as a dependency.","message":"Installation of 'netCDF4' (a common xarray backend) may fail in Alpine Linux environments due to missing HDF5 development headers. The build process for 'netCDF4' requires system-level HDF5 development libraries.","severity":"breaking","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2026':67 '2026.2.0':72 'analysi':59,90 'array':6,22,43,96 'attribut':35 'bi':87 'bi-month':86 'cadenc':78 'comput':56,92 'coordin':33 'current':69 'data':58,89 'dataset':24 'dimens':32 'dimension':21 'earth':62 'enabl':44 'error':51 'error-pron':50 'ex':5 'ex-array':4 'experi':53 'februari':66 'form':30 'geospati':98 'introduc':26 'intuit':47 'label':18,27,95 'less':49 'like':42 'maintain':74 'minor':80 'month':84,88 'multi':20 'multi-dimension':19 'multidimension':97 'netcdf':93 'numpi':41 'numpy-lik':40 'open':10 'open-sourc':9 'packag':13 'particular':60 'prone':52 'pronounc':3 'python':12 'raw':39 'regular':76 'releas':77,83 'scienc':63 'scientif':55,91 'simplifi':15 'sourc':11 'top':37 'typic':82 'version':70,81 'work':16 'xarray':1,2,73 'zarr':94","created_at":"2026-04-05T13:07:37.962839+00:00","updated_at":"2026-04-17T00:49:34.447848+00:00","problems":[{"fix":"Install the appropriate backend library using `pip install netcdf4` (or `h5netcdf`, `zarr`, `cfgrib`, etc., as needed for your file type).","cause":"The required backend library (e.g., `netcdf4`, `h5netcdf`, `zarr`) for reading or writing a specific file format is not installed in the Python environment.","error":"ValueError: Cannot find the h5netcdf, netcdf4 or pydap backend. Please install one of them to use 'netcdf' engine."},{"fix":"Ensure dimensions and coordinates align appropriately, or use `xarray.concat()` with `coords='minimal'` or `compat='override'` if conflicts are expected, or explicitly select/rename variables/dimensions before merging.","cause":"Attempting to merge or concatenate `xarray.Dataset` or `xarray.DataArray` objects that have conflicting dimensions for variables, or non-matching coordinates along a dimension when a strict compatibility check is used.","error":"ValueError: encountered differing variable dimensions that cannot be reconciled"},{"fix":"Verify the exact name of the coordinate or variable using `ds.coords`, `ds.data_vars`, or `ds.dims` (for Dataset) or `da.coords` (for DataArray) and use the correct name in your selection.","cause":"An attempt was made to select or access a coordinate or variable using a name that does not exist in the `Dataset` or `DataArray`.","error":"KeyError: 'some_coordinate_or_variable_name'"},{"fix":"Ensure operands have compatible numeric data types using `.astype()`, explicitly align dimensions using `.align()`, or compute Dask arrays to concrete NumPy arrays using `.compute()` if the operation requires it.","cause":"An arithmetic operation (like subtraction) was attempted between `xarray.DataArray` or `xarray.Dataset` objects (often backed by Dask arrays) that have incompatible data types, unaligned dimensions, or involve an operation not supported by the underlying ufunc for the given types.","error":"TypeError: ufunc 'subtract' did not contain a loop with signature matching types"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2026.7.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://xarray.dev/","github":"https://github.com/pydata/xarray","docs":"https://docs.xarray.dev","changelog":null,"pypi":"https://pypi.org/project/xarray/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}