pydata / pydata/xarray

String type casting error during concatenating

Open
#10,968 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs triage topic-combine
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

I have a very large number of data sets (6840) that I want to concat over 3 dimensions. An example of one of the dataset is showed below:

Image

I concat with:

        (
            xr.concat(dss, "case")
            .set_index(dict(case=["wave_seed", "site_id", "damping_case"]))
            .unstack()
        )

after concatenating my dataset looks like this:

Image

Note that 'NC100 (OSS)' has tuned into 'NC100' and 'base_case' has turned into 'base_c'. This is due to truncation since the dtype also change from U9 and U11 to U5 and U6. If I add the following before concating this issue is resolved.

                ds['site_id'] = ds['site_id'].astype("U12")
                ds['damping_case'] = ds['damping_case'].astype("U10")

I cannot reproduce with a smaler number of datasets so not sure how to reproduce this bug.

What did you expect to happen?

No response

Minimal Complete Verifiable Example
# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# ]
# ///
#
# This script automatically imports the development branch of xarray to check for issues.
# Please delete this header if you have _not_ tested this script with `uv run`!

import xarray as xr
xr.show_versions()
# your reproducer code ...
Steps to reproduce

No response

MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 11
machine: AMD64
processor: Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: ('English_United States', '1252')
libhdf5: 1.14.6
libnetcdf: None

xarray: 2025.6.0
pandas: 2.3.0
numpy: 2.2.6
scipy: 1.15.3
netCDF4: None
pydap: None
h5netcdf: 1.6.1
h5py: 3.14.0
zarr: 3.0.8
cftime: None
nc_time_axis: None
iris: None
bottleneck: 1.5.0
dask: 2025.5.1
distributed: 2025.5.1
matplotlib: 3.10.3
cartopy: None
seaborn: 0.13.2
numbagg: 0.9.0
fsspec: 2025.5.1
cupy: None
pint: 0.24.4
sparse: None
flox: 9.11
numpy_groupies: 0.11.3
setuptools: 80.9.0
pip: 25.1.1
conda: None
pytest: 8.0.2
mypy: 1.16.0
IPython: 9.3.0
sphinx: 8.3.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported xr.concat, set_index, and unstack entry points and investigate how string dtypes change when concatenating thousands of datasets. Reproduce the truncation with a complete, runnable example and verify that the resulting site_id and damping_case values retain their full strings without manual astype calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, pandas, python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.