Skip to content

Remove redundant asserts#95

Open
lispandfound wants to merge 1 commit intopegasusfrom
fix_gcmt_to_realisation
Open

Remove redundant asserts#95
lispandfound wants to merge 1 commit intopegasusfrom
fix_gcmt_to_realisation

Conversation

@lispandfound
Copy link
Contributor

These assert statements were breaking gcmt-to-realisation because the values had type np.float64 not float, so I have removed the assertions

Copilot AI review requested due to automatic review settings March 10, 2026 01:31
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a runtime issue in the gcmt-to-realisation script by removing type assertion statements that were causing failures. The assertions incorrectly expected standard Python float types, while the actual values were numpy.float64, leading to unnecessary program interruptions. The removal of these checks ensures the script can process numpy float types without error, improving its robustness.

Highlights

  • Type Assertion Removal: Removed redundant isinstance type assertions for nodal plane parameters (strike, dip, rake) in gcmt_to_realisation.py.
  • Bug Fix: Resolved a runtime issue where these assertions were incorrectly failing for numpy.float64 values, which are distinct from Python's built-in float type.
Changelog
  • workflow/scripts/gcmt_to_realisation.py
    • Removed isinstance assertions for strike1, dip1, rake1, strike2, dip2, and rake2 variables.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes runtime assert isinstance(...) checks in gcmt-to-realisation that were failing when values are np.float64, allowing GCMT CSV-derived nodal-plane values to flow through without hard type assertions.

Changes:

  • Removed six isinstance(..., float | int) asserts for strike/dip/rake values read from the published GCMT CSV.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

assert isinstance(dip2, float | int)
assert isinstance(rake2, float | int)
nodal_plane_1 = NodalPlane(strike1, dip1, rake1)
nodal_plane_2 = NodalPlane(strike2, rake2, dip2)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

nodal_plane_2 is constructed with arguments in a different order than nodal_plane_1 (and likely the NodalPlane API). Here it passes (strike2, rake2, dip2), which swaps dip and rake and will produce an incorrect nodal plane; use the same (strike, dip, rake) ordering as for plane 1 (and as implied by NodalPlane(**solution["nodalPlanes"][1])).

Suggested change
nodal_plane_2 = NodalPlane(strike2, rake2, dip2)
nodal_plane_2 = NodalPlane(strike2, dip2, rake2)

Copilot uses AI. Check for mistakes.
assert isinstance(strike2, float | int)
assert isinstance(dip2, float | int)
assert isinstance(rake2, float | int)
nodal_plane_1 = NodalPlane(strike1, dip1, rake1)
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

This PR removes type asserts for strike/dip/rake because pandas returns np.float64, but there are still asserts later in this function (assert isinstance(magnitude, float) and assert isinstance(centroid_depth, float)) that will also fail for np.float64 (and potentially int). Consider removing these asserts too, or replacing them with a numbers.Real/np.floating check or explicit float(...) conversion at the point of use.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes several assert statements that were causing issues due to type mismatches with numpy data types. While this fixes the immediate problem, it also removes valuable type validation. My review suggests reintroducing these assertions with a more robust type check that accommodates numpy's numeric types, ensuring both correctness and robustness without causing crashes.

I am having trouble creating individual review comments. Click here to see my feedback.

workflow/scripts/gcmt_to_realisation.py (174-179)

medium

While these assertions were failing due to np.float64 types, removing them entirely eliminates important type validation. This could lead to unexpected errors downstream if the data is not numeric. A better approach is to modify the assertions to correctly handle numpy's numeric types. You can include np.number in the type check, which is a base type for numpy's numeric scalars.

        assert isinstance(strike1, (int, float, np.number))
        assert isinstance(dip1, (int, float, np.number))
        assert isinstance(rake1, (int, float, np.number))
        assert isinstance(strike2, (int, float, np.number))
        assert isinstance(dip2, (int, float, np.number))
        assert isinstance(rake2, (int, float, np.number))

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