Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the validate_output_table_type function to check the output_type parameter #2772

Merged
merged 5 commits into from
Oct 30, 2023

Conversation

seisman
Copy link
Member

@seisman seisman commented Oct 27, 2023

Description of proposed changes

Add the validate_output_type function so it can be re-used in many modules.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@seisman seisman force-pushed the validators/output_type branch 3 times, most recently from e9500eb to c5b90fa Compare October 27, 2023 03:22
@seisman seisman changed the title Add the validate_output_type function to check the output_type parameter RFC: Add the validate_output_type function to check the output_type parameter Oct 27, 2023
@seisman seisman added maintenance Boring but important stuff for the core devs needs review This PR has higher priority and needs review. and removed needs review This PR has higher priority and needs review. labels Oct 27, 2023
@seisman seisman added this to the 0.11.0 milestone Oct 27, 2023
@seisman seisman added the needs review This PR has higher priority and needs review. label Oct 27, 2023
Co-authored-by: Yvonne Fröhlich <[email protected]>
@seisman seisman changed the title RFC: Add the validate_output_type function to check the output_type parameter Add the validate_output_type function to check the output_type parameter Oct 28, 2023
@seisman seisman requested a review from a team October 28, 2023 08:41
@seisman
Copy link
Member Author

seisman commented Oct 29, 2023

Ping @GenericMappingTools/pygmt-maintainers for review.

pygmt/src/grdhisteq.py Outdated Show resolved Hide resolved
@@ -13,6 +12,7 @@
fmt_docstring,
kwargs_to_strings,
use_alias,
validate_output_type,
Copy link
Member

Choose a reason for hiding this comment

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

Just on the naming, should we specify that this applies to tabular outputs? E.g. use something like validate_output_table_type? There are some functions like pygmt.grdhisteq.equalize_grid that has code looking like this:

with GMTTempFile(suffix=".nc") as tmpfile:
    if isinstance(outgrid, str):
        output_type = "file"
    elif outgrid is None:
        output_type = "xarray"
        outgrid = tmpfile.name
    else:
        raise GMTInvalidInput("Must specify 'outgrid' as a string or None.")

If we ever decide to have more output_types for grids (e.g. NetCDF or TIFF or xarray or ???), then there might be a validate_output_grid_type.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about adding a new parameter kind (valid values are dataset/grid) to make the function working for both tables and grids.

Copy link
Member

Choose a reason for hiding this comment

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

There would a lot of if-thens, and the error/warning messages would be different between tables and grids though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah right, tables use outfile but grids use outgrid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just on the naming, should we specify that this applies to tabular outputs? E.g. use something like validate_output_table_type?

Renamed in becbb73.

@weiji14 weiji14 added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Oct 30, 2023
@seisman seisman changed the title Add the validate_output_type function to check the output_type parameter Add the validate_output_table_type function to check the output_type parameter Oct 30, 2023
@seisman seisman merged commit 8f1d476 into main Oct 30, 2023
14 checks passed
@seisman seisman deleted the validators/output_type branch October 30, 2023 14:50
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants