Skip to content

Major performance regression in Coordinates.to_index() #11305

@y4n9squared

Description

@y4n9squared

What happened?

Commit a13a255#diff-c73f63e529ab4065cca1aa23d93c91a3b060f314e2e498b708b90fef87141a88 which attempts to fix some type hint issues also introduced a major performance regression in Coordinate.to_index() (mostly felt in to_dataframe()) by changing the code_list variable being cache-friendly ndarray to Python lists.

What did you expect to happen?

I expect this to be near instantaneous like it was in 2025.8.0 but now it takes close to 10s on my machine.

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()

import numpy as np
import xarray as xr

da = xr.DataArray(np.arange(100 * 2000 * 300).reshape(100, 2000, 300), name="foo")
da.to_dataframe()

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

Details

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageIssue that has not been reviewed by xarray team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions