Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Issue with `.sel` and `PintIndex` when using kwarg `method="nearest"`

オープン
#303 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
data

調査の方向性

Start by running the minimal example with Python, xarray, and pint-xarray, then inspect the PintIndex.sel entry point reported in the traceback. The issue is done when q.sel(lat=74 * ureg.degrees, method="nearest") succeeds without the unexpected-keyword error and selects the nearest coordinate.

索引モデルが issue の本文から書いたものです。

説明

I have tried using the latest version of pint-xarray==0.5.0 which includes units in the coordinates which is exciting but I believe I have found an issue when using .sel and the kwarg method="nearest", which would be used when selecting data nearest to the coordinate value specified but not exactly on the grid.

My guess is that the kwargs are not being passed correctly. Maintaining this functionality would be incredibly useful and hopefully an easy fix.

See a minimal working example below

import xarray as xr
import pint_xarray

ureg = pint_xarray.unit_registry
ds = xr.tutorial.open_dataset("air_temperature")
q = ds.pint.quantify({"lat": "degrees", "lon": "degrees"})

q_75 = q.sel(lat=75 * ureg.degrees)
q_74 = q.sel(lat=74 * ureg.degrees, method="nearest")

which fails with this error

Traceback (most recent call last):
  File "/home/ir-pate3/pyro_testing/mwe_pint_xarray.py", line 10, in <module>
    q_74 = q.sel(lat=74 * ureg.degrees, method="nearest")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ir-pate3/.local/lib/python3.11/site-packages/xarray/core/dataset.py", line 3249, in sel
    query_results = map_index_queries(
                    ^^^^^^^^^^^^^^^^^^
  File "/home/ir-pate3/.local/lib/python3.11/site-packages/xarray/core/indexing.py", line 194, in map_index_queries
    results.append(index.sel(labels, **options))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: PintIndex.sel() got an unexpected keyword argument 'method'

Currently using pint-xarray=0.5.0 and xarray=2024.11.0.

See related issue here where this breaks our CI tests.
https://github.com/pyro-kinetics/pyrokinetics/issues/446

主要言語
Python
スター
119
フォーク
16
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

xarray-contrib/pint-xarray のほかの issue

xarray-contrib/pint-xarray の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。