Skip to content

The incols parameter does not always work for pandas.DataFrame #1440

Closed
GenericMappingTools/gmt
#5989

Description

@maxrjones

Description of the problem

Under certain cases, the incols (-i) parameter does not work to swap the input columns. From the best that I can tell, the bug happens when there are floats in both columns.

Full code that generated the error

## Test incols (-i) option
# Create some data in a dataframe
data_incols = pd.DataFrame(data={'col1': [-0.5, 0, 0.5], 'col2': [-0.75, 0, 0.75]})
# Write the data to a file
data_incols.to_csv(path_or_buf="data_incols.txt", sep=" ", index=False, header=False) 

# Test passing data in a virtual file
fig = pygmt.Figure()
# Plot the dataframe data
fig.plot(data=data_incols, frame=True, region="-1/1/-1/1", projection="X5c", incols="1,0")
fig.savefig("test_i1_virtual.png")

# Test passing data in a file
fig = pygmt.Figure()
# Plot the file data
fig.plot(data="data_incols.txt", frame=True, region="-1/1/-1/1", projection="X5c", incols="1,0") 
fig.savefig("test_i1_file.png")

Expected outcome

Two files with the same plot

Actual outcome

Test with virtual file:

test_i1_virtual

Test with ASCII file:

test_i1_file

Full error message

No error message

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.4.2.dev4+gebbb0cc0.d20210811
System information:
  python: 3.9.6 | packaged by conda-forge |  [Clang 11.1.0 ]
  executable:anaconda-03/anaconda3/envs/pygmt/bin/python
  machine: macOS-11.5-x86_64
Dependency information:
  numpy: 1.21.1
  pandas: 1.3.1
  xarray: 0.19.0
  netCDF4: 1.5.7
  packaging: 21.0
  ghostscript: 9.54.0
  gmt: 6.2.0

Activity

  1. added
    bug
    upstream
    on Aug 11, 2021
  2. maxrjones commented on Aug 11, 2021

    @maxrjones
    MemberAuthor

    I have a few bugs similar to this for various lower-case common options. Does anyone have advice for whether I should open these bug reports in the PyGMT or GMT repository? I'm confident they are upstream bugs, but at the same time I do not expect that we would be able to reproduce them without debugging through PyGMT first.

  3. self-assigned this
    on Nov 10, 2021
  4. maxrjones commented on Nov 12, 2021

    @maxrjones
    MemberAuthor

    Fixed by GenericMappingTools/gmt#5989, but reopening to add a regression test.

  5. added this to the 0.6.0 milestone on Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugupstream

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions