Skip to content

Conversation

@Nanakjoth
Copy link

Summary

Add a simple check in load_oasis_montaj_grid to raise a clear ValueError if the number of grid elements does not match the expected shape. This helps users quickly see if a .grd file is corrupted or incomplete.


What changed

  • Added an explicit element count check before .reshape().
  • Raises a clear error instead of NumPy’s reshape error.
  • Manually tested by creating a fake .grd with missing elements.

Closes #451.

@santisoler
Copy link
Member

santisoler commented Jul 16, 2025

Hi @Nanakjoth. Thanks for taking the time to work on this and opening the PR!

I like the error message you added. Before we merge this PR I would like to add some test that checks that the error is being raised when a corrupted file has been passed. We could add the sample corrupted file you used to manually test the function to harmonica/tests/data, name it something like incomplete_grid.grd, and add a test function in harmonica/tests/test_oasis.py that tries to load the file and checks your error was raised. We can use pytest.raises to run the check.

Would you like to work on that test?

@Nanakjoth
Copy link
Author

Hi @santisoler,
Absolutely, I would love to do it.

I actually thought about adding it at the same time as the fix but didn’t get around to it, so thanks for suggesting, that helps a lot.

Will update the PR shortly! 🚀

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.

Raise error when GRD file is corrupted

2 participants