Improve `Dataset.map` `keep_attrs`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
This is an open API design question, not a ready task: the issue asks maintainers to choose between three options for Dataset.map's keep_attrs. Start by reading the linked #11020, #11019 and #10726 threads to see what was already decided. Done means a maintainer-agreed design, so a newcomer should comment on the issue and wait for direction before writing code.
由索引模型根据 Issue 内容生成。
描述
What is your issue?
Follow-up to #11020 / #11019.
Since #10726 (v2025.11.0) Dataset.map has no way to keep attributes set by the mapped function: keep_attrs=True overwrites them with the original attrs, keep_attrs=False drops them. #11020 fixes this regression by leaving the function's attrs alone for keep_attrs=False and merging with drop_conflicts for keep_attrs=True. The discussion there showed that the boolean keep_attrs is the wrong interface for map:
- The function receives xarray objects, so it can handle attrs itself.
keep_attrsmainly gets in the way of that (@dcherian, @max-sixty). - Coordinates can still be modified inside the function, so the coordinate attrs of the results need to be combined somehow. That is what the argument should control instead, e.g. as
combine_attrs(@jsignell, @dcherian). - A boolean
keep_attrsis ambiguous: doesFalsemean "drop the input attrs" or "drop all attrs on the output"? (@keewis, @jsignell; see also #10997) mapis basically a loop over.data_vars, and users who need full control can do that loop themselves, e.g.ds.assign({name: func(var) for name, var in ds.data_vars.items()})orxr.merge(..., combine_attrs=...)(@keewis, @jsignell).- Before deprecating
keep_attrs, users need a way to opt into the new behavior (@keewis, @jsignell).
Options discussed for that:
- Add
combine_attrstomap, accepting the usual strategy names / a callable, and deprecatekeep_attrs. This is the option @keewis and @jsignell leaned towards. - Let
keep_attrsaccept strategy names / a callable, likeapply_ufunc, mappingTrueto"override"andFalseto"drop". This avoids a new argument, but a single value can't then control data variable and coordinate attrs separately. - Remove
keep_attrsfrommapwithout replacement and keep whatever attrs the function returns.
- 主要语言
- Python
- 星标
- 4.2k
- 派生
- 1.5k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 74
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
维护者通常 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
维护者通常 1 天内回复
-
RangeIndex` with datetime64 bounds cannot be printed (`Unknown format code 'g'`)可能已有人在做 @d-chambers 于 60 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 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
维护者通常 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 天内回复