Skip to content

Improve robustness by safely accessing metadata using dict.get#175

Open
tejasnarwade wants to merge 3 commits intosunpy:mainfrom
tejasnarwade:improve-rpw-metadata-safety
Open

Improve robustness by safely accessing metadata using dict.get#175
tejasnarwade wants to merge 3 commits intosunpy:mainfrom
tejasnarwade:improve-rpw-metadata-safety

Conversation

@tejasnarwade
Copy link
Copy Markdown

@tejasnarwade tejasnarwade commented Mar 17, 2026

This PR improves robustness in RPWSpectrogram by replacing direct dictionary access (meta["instrument"]) with meta.get("instrument").

This prevents potential KeyError exceptions when the "instrument" key is missing, making the code more resilient to incomplete metadata.
This was small change but still i think prevention is better than cure so i pushed the pr
The behavior remains unchanged when the key is present.

PR Description
AI Assistance Disclosure
AI tools were used for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding
  • No AI tools were used**

@samaloney
Copy link
Copy Markdown
Member

samaloney commented Mar 27, 2026

Thanks for the PR but I'm not sure we want to do this, if the metadata isn't there it indicates problem with the source file and these changes would hide that.

Also do you have an example of this happening in the real world? I think I'd like to see a failing test case on real data before proceeding down this route.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants