Skip to content

Function for retrieving fault planes - #18

Open
claudio525 wants to merge 1 commit into
mainfrom
minor_mod
Open

Function for retrieving fault planes#18
claudio525 wants to merge 1 commit into
mainfrom
minor_mod

Conversation

@claudio525

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces the get_fault_planes method to the NSHMDB class for retrieving and converting fault plane coordinates, alongside minor docstring and formatting fixes. Feedback was provided regarding the use of SELECT * and positional unpacking, which is fragile; the reviewer suggested explicitly selecting columns and iterating over the cursor directly for improved robustness and memory efficiency.

Comment thread nshmdb/nshmdb.py
Comment on lines +266 to +283
cursor.execute(
"SELECT * from fault_plane where fault_id = ?", (fault_id,)
)
planes = []
for (
_,
top_left_lat,
top_left_lon,
top_right_lat,
top_right_lon,
bottom_right_lat,
bottom_right_lon,
bottom_left_lat,
bottom_left_lon,
top,
bottom,
_,
) in cursor.fetchall():

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.

medium

Using SELECT * with positional unpacking is fragile and can lead to runtime errors if the database schema is modified (e.g., if columns are added or reordered). It is better to explicitly select the required columns and unpack them directly. Additionally, iterating over the cursor directly is more memory-efficient than using fetchall().

            cursor.execute(
                "SELECT top_left_lat, top_left_lon, top_right_lat, top_right_lon, "
                "bottom_right_lat, bottom_right_lon, bottom_left_lat, bottom_left_lon, "
                "top_depth, bottom_depth FROM fault_plane WHERE fault_id = ?",
                (fault_id,),
            )
            planes = []
            for (
                top_left_lat,
                top_left_lon,
                top_right_lat,
                top_right_lon,
                bottom_right_lat,
                bottom_right_lon,
                bottom_left_lat,
                bottom_left_lon,
                top,
                bottom,
            ) in cursor:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doing this could be good, seems simple enough change

@joelridden joelridden left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Need to add a simple test case for the test coverage

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