Registry Mirror
Skip to content

Conversation

@sfinkens

@sfinkens sfinkens commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

Following up on the discussion in #11636, add a small paragraph to the user guide explaining that you can also use variable attributes for encoding.

My use case is forcing xarray to create a variable using netCDF4.Dataset.createVariable(..., fill_value=False). This cannot be achieved via the encoding argument, because then xarray casts the fill value to the numerical data type of the variable (which is fine I think).

@kmuehlbauer kmuehlbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfinkens It might just work for _FillValue since it has some special casing in variable preparation. Maybe this needs some adaption in the wording.

@kmuehlbauer kmuehlbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sfinkens I've turned your added paragraph into an admonition (caution). It's more visible. Also I tested this with packed data (scale_factor and add_offset attributes). It works, if the variable in question has the needed dtype in encoding.

Comment thread doc/user-guide/io.md Resolved
@kmuehlbauer kmuehlbauer added the plan to merge Final call for comments label Oct 2, 2026
@headtr1ck

Copy link
Copy Markdown
Collaborator

I'm not too familiar with RTS, but it seems to fail with: WARNING: Pygments lexer name 'caution' is not known [misc.highlighting_failure]

Change language identifier from "caution" to "note"
@sfinkens

sfinkens commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the delayed response, and thanks for verifying that it also works for other encoding options. I've changed the language identifier from caution to {note}. Let me know if you prefer {warning}.

@kmuehlbauer

Copy link
Copy Markdown
Contributor

We may leave it as note, but that looks always like normal/general recommendation.

Maybe a warning is appropriate? What would a user make most out of it?

@sfinkens

sfinkens commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

I just searched for warnings in the user guide and they are used in "this works but be careful" situations. I think in that sense it is appropriate to use a warning here as well.

Change language identifier from "note" to "warning"
@headtr1ck
headtr1ck merged commit ba0f485 into pydata:main Oct 6, 2026
46 checks passed
@welcome

welcome Bot commented Oct 6, 2026

Copy link
Copy Markdown

Congratulations on completing your first pull request! Welcome to Xarray! We are proud of you, and hope to see you again! celebration gif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants