GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — x2sys_cross: Fix IndexError to allow empty dataframe outputs by weiji14 · Pull Request #4060 · GenericMappingTools/pygmt

Conversation

@weiji14

@weiji14 weiji14 commented Aug 21, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

Fixes IndexError: index 0 is out of bounds for axis 0 with size 0 when x2sys_cross returns no crossovers. An empty dataframe should be returned instead.

Full traceback:

___________________ test_x2sys_cross_output_dataframe_empty ____________________

self = RangeIndex(start=0, stop=0, step=1), key = 0

    def __getitem__(self, key):
        """
        Conserve RangeIndex type for scalar and slice keys.
        """
        if isinstance(key, slice):
            return self._getitem_slice(key)
        elif is_integer(key):
            new_key = int(key)
            try:
>               return self._range[new_key]
                       ^^^^^^^^^^^^^^^^^^^^
E               IndexError: range object index out of range

../../../../micromamba/envs/pygmt/lib/python3.11/site-packages/pandas/core/indexes/range.py:982: IndexError

The above exception was the direct cause of the following exception:

tracks = [              x         y     z
4152  251.11450  25.22122 -19.0
4380  249.61510  24.30340 -19.0
5033  249.36575  27.34900 -19.0
5034  249.36971  27.34747 -19.0
9589  249.72477  24.39497 -13.0]

    @pytest.mark.benchmark
    @pytest.mark.usefixtures("mock_x2sys_home")
    def test_x2sys_cross_output_dataframe_empty(tracks):
        """
        Test that x2sys_cross can output an empty dataframe (when there are no crossovers)
        without any errors.
    
        Regression test for
        https://forum.generic-mapping-tools.org/t/issue-with-x2sys-in-pygmt-solved/6154
        """
        with TemporaryDirectory(prefix="X2SYS", dir=Path.cwd()) as tmpdir:
            tag = Path(tmpdir).name
            x2sys_init(tag=tag, fmtfile="xyz", force=True)
    
            tracks = [tracks[0][:5]]  # subset to less rows so there won't be crossovers
>           output = x2sys_cross(tracks=tracks, tag=tag, coe="i")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

../pygmt/tests/test_x2sys_cross.py:328: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../pygmt/helpers/decorators.py:590: in new_module
    return module_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../pygmt/helpers/decorators.py:756: in new_module
    return module_func(*bound.args, **bound.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../pygmt/src/x2sys_cross.py:256: in x2sys_cross
    if columns[0][0] == "t":  # "t" or "i":
       ^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = RangeIndex(start=0, stop=0, step=1), key = 0

    def __getitem__(self, key):
        """
        Conserve RangeIndex type for scalar and slice keys.
        """
        if isinstance(key, slice):
            return self._getitem_slice(key)
        elif is_integer(key):
            new_key = int(key)
            try:
                return self._range[new_key]
            except IndexError as err:
>               raise IndexError(
                    f"index {key} is out of bounds for axis 0 with size {len(self)}"
E                   IndexError: index 0 is out of bounds for axis 0 with size 0

../../../../micromamba/envs/pygmt/lib/python3.11/site-packages/pandas/core/indexes/range.py:984: IndexError

Fixes https://forum.generic-mapping-tools.org/t/issue-with-x2sys-in-pygmt-solved/6154, patches bug introduced in #3182 (pygmt v0.13.0 - v0.16.0)

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.

Slash Commands

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

  • /format: automatically format and lint the code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@weiji14
Add regression test to ensure x2sys_cross can output empty dataframe
d9b0051
Fixes `IndexError: index 0 is out of bounds for axis 0 with size 0` when x2sys_cross returns no crossovers. An empty dataframe should be returned instead.
@weiji14 weiji14 added this to the 0.17.0 milestone Aug 21, 2025
@weiji14 weiji14 self-assigned this Aug 21, 2025
@weiji14 weiji14 added the bug Something isn't working label Aug 21, 2025
@weiji14
Only perform timestamp post-processing when dataframe is not empty
b3a9fbc
Avoid checking of column names when the dataframe is empty due to no available crossovers.
@weiji14 weiji14 changed the title Add regression test to ensure x2sys_cross can output empty dataframe x2sys_cross: Fix IndexError to allow empty dataframe outputs Aug 21, 2025
@weiji14
weiji14 marked this pull request as ready for review August 21, 2025 01:59
seisman
seisman approved these changes Aug 21, 2025
View reviewed changes
weiji14
weiji14 commented Aug 21, 2025
View reviewed changes
Comment thread pygmt/tests/test_x2sys_cross.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@weiji14
Update pygmt/tests/test_x2sys_cross.py
61819bd
@weiji14
weiji14 enabled auto-merge (squash) August 21, 2025 04:47
@weiji14
weiji14 merged commit 4c6a1f8 into main Aug 21, 2025
@weiji14
weiji14 deleted the x2sys_empty_df branch August 21, 2025 04:54
@seisman seisman mentioned this pull request Jul 26, 2026
Track progress of wrapping GMT modules #4765
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@seisman seisman seisman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@weiji14 weiji14

Labels

bug Something isn't working

Projects

None yet

Milestone

0.17.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@weiji14 @seisman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.