Fix notebook `intermediate/indexing/why-an-index.ipynb`

未关闭 适合新手
#376 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
jupyter-notebook, python
领域
data

调研方向

打开 intermediate/indexing/why-an-index.ipynb 并从头到尾运行它,重点关注 Cell In[16],其中 periodic.sel(angle=q) 会生成一个包含单个元素的 angle 维度。检查数组输入的索引行为并更新 notebook,使绘制的值与 q 的 721 个元素相匹配;在没有出现所报告的维度错误的情况下重新运行完整 notebook 即完成此项工作。

由索引模型根据 Issue 内容生成。

描述

This notebook (looking at 54df4e2fc01e51905210793f7aa01df0d87be86b ) doesn't run top to bottom

Cell In[16], [line 7](vscode-notebook-cell:?execution_count=16&line=7)
      3 periodic_temp = periodic.sel(angle=q)
      4 
      5 fig, ax = plt.subplots(figsize=(9, 4))
      6 ax.scatter(sensor_fold, metal_ring.values, color="0.3", s=45, zorder=5, label="the sensors")
----> [7](vscode-notebook-cell:?execution_count=16&line=7) ax.plot(q, periodic_temp, color="tab:green", lw=2.5, label="PeriodicIndex .sel")
      8 ax.plot(q, default_temp, color="tab:red", lw=2, label="default index")
      9 ax.axvline(0, color="0.6", ls=":", lw=1)
     10 ax.set_xlabel("query angle (°)")

File ~/coding/repos/xarray-tutorial/.pixi/envs/default/lib/python3.14/site-packages/matplotlib/axes/_axes.py:1792, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)
   1549 """
   1550 Plot y versus x as lines and/or markers.
   1551 
   (...)   1789 (``'green'``) or hex strings (``'#008000'``).
   1790 """
   1791 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> [1792](https://file+.vscode-resource.vscode-cdn.net/Users/Hodgs004/coding/repos/xarray-tutorial/intermediate/indexing/~/coding/repos/xarray-tutorial/.pixi/envs/default/lib/python3.14/site-packages/matplotlib/axes/_axes.py:1792) lines = [*self._get_lines(self, *args, data=data, **kwargs)]
   1793 for line in lines:
   1794     self.add_line(line)

File ~/coding/repos/xarray-tutorial/.pixi/envs/default/lib/python3.14/site-packages/matplotlib/axes/_base.py:331, in _process_plot_var_args.__call__(self, axes, data, return_kwargs, *args, **kwargs)
    329     this += args[0],
...
    511 if x.ndim > 2 or y.ndim > 2:
    512     raise ValueError(f"x and y can be no greater than 2D, but have "
    513                      f"shapes {x.shape} and {y.shape}")

ValueError: x and y must have same first dimension, but have shapes (721,) and (1,)

I don't think the index is working as expected when angle is an array input.

periodic_temp = periodic.sel(angle=q) # `q.shape` is `(721,)`
# but `periodic_temp.sizes` is `Frozen({'angle': 1})`

cc @ianhi

主要语言
Jupyter Notebook
星标
204
派生
121
PR 合并指标
30 天内没有已合并 PR

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

xarray-contrib/xarray-tutorial 的其他 Issue

查看 xarray-contrib/xarray-tutorial 的全部 Issue

相似的 Issue

更多 Data Engineering Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。