Feat: Add a mechanism for Serializing any index - `to_zarr` on a big RangeIndex causes a crash
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、issue の例を使って RangeIndex.arange、Coordinates.from_xindex、to_zarr、open_zarr での動作を再現します。インデックスのシリアライズ経路を追跡し、カスタムインデックスの復元と適切なフォールバックがどのように機能すべきかを判断します。利用可能なインデックスを保持したまま、非常に大きな座標配列を実体化しないことが完了の条件です。
索引モデルが issue の本文から書いたものです。
説明
Is your feature request related to a problem?
As I understand it the current way that indexes are serialized is by writing the full contents of their coords to disk. This has some admirable properties in terms of interoperability with other tools and backcompatibility, but also some pitfalls.
1. Places burden on user's of xarray to remember re-install the index after loading + no mechanism for remembering what coords had set_xindex called on them.
A simple example:
import xarray as xr
ds = xr.Dataset(
{"data": ("time", [0, 1, 2, 3])},
coords={"time": [0.1, 0.2, 0.3, 0.4], "time_metadata": ("time", [10, 15, 20, 25])},
).set_xindex("time_metadata")
ds
ds.to_zarr("extra_index.zarr", mode="w")
roundtripped = xr.open_zarr("extra_index.zarr")
assert len(ds.xindexes) == len(roundtripped.xindexes)
fails with an assertion error.
2. For lazy indexes it's possible to crash your computer or run out of disk space with a simple to_zarr
For example, this snippet will create a 120 MiB zarr store when
import xarray as xr
step="1e-5"
idx1 = xr.indexes.RangeIndex.arange(0.0, 1000.0, float(step), dim="x")
ds1 = xr.Dataset(coords=xr.Coordinates.from_xindex(idx1))
ds1.to_zarr(f"float_range_step_{step}.zarr")
and I had to restart my laptop to get it unfrozen after running the below (offending line commented out) with the step value from the example (https://xarray-indexes.readthedocs.io/builtin/range.html)
import xarray as xr
step="1e-9"
idx1 = xr.indexes.RangeIndex.arange(0.0, 1000.0, float(step), dim="x")
ds1 = xr.Dataset(coords=xr.Coordinates.from_xindex(idx1))
# ds1.to_zarr(f"float_range_step_{step}.zarr")
Describe the solution you'd like
Allow indexes more control over how they are serialized and support a mechanism for automatically re-creating them if they are available in the current environment, with a graceful fallback.
Describe alternatives you've considered
If writing a custom index you could write your own loading function, but that would not solve the coord-bomb behavior and places more friction on the user.
Additional context
No response
- 主要言語
- Python
- スター
- 4.2k
- フォーク
- 1.5k
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 74
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pydata/xarray のほかの issue
-
xarray removes axis grid from pcolormesh対応中かも @Sealdot が今日担当しました。 オープンbug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
`DataTree.map_over_datasets` behavior can be obscure sometimes対応中かも @mohansree14 が 24 日前に担当しました。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pydata/xarray#11813 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Comparing attrs that contain a dict of NumPy arrays raises ValueError in identical / assert_identical対応中かも @SohamXYZDev が 29 日前に担当しました。 オープンbug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
pydata/xarray#11777 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
RangeIndex` with datetime64 bounds cannot be printed (`Unknown format code 'g'`)対応中かも @d-chambers が 60 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pydata/xarray#11598 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
DataTree constructor error message says dict even though dict is not accepted対応中かも @aryansk が 100 日前に担当しました。 オープンbug contrib-good-first-issue topic-DataTree topic-error reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
pydata/xarray#11514 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
abetlen/llama-cpp-python#2424 ·
メンテナーはふだん 1 日以内に返信
-
Bug IronPython Python 3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
pyrevitlabs/pyRevit#4184 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信