Skip to content

Bug in importing dataset with mixed types for external wrappers #3330

Closed

Description

@seisman

The bug was first reported in PyGMT GenericMappingTools/pygmt#255. After tracking it down, I realize that it actually is a GMT bug.

The minimal example to reproduce the bug is:

import pygmt

fig = pygmt.Figure()
fig.plot(x=[1.0, 3.0], y=[2, 4], pen="1p,gray,-", region='0/10/0/10', frame=True)
fig.savefig("map.png")

I can't reproduce the bug using GMT command line or GMT.jl, possibly because they read data in different ways.

Here is the output of the above Python script. Obviously, it's wrong.
image

The buggy codes are shown below:

gmt/src/gmt_api.c

Lines 4017 to 4025 in 3f11b48

for (col = 1, diff_types = false; !diff_types && col < V_obj->n_columns; col++) if (V_obj->type[col] != V_obj->type[col-1]) diff_types = true;
api_get_val = gmtapi_select_get_function (API, V_obj->type[0]);
for (row = seg = n_records = 0; row < V_obj->n_rows; row++) { /* This loop may include NaN-records and data records */
n_use = gmtapi_n_cols_needed_for_gaps (GMT, V_obj->n_columns);
gmtapi_update_prev_rec (GMT, n_use);
for (col = 0; col < V_obj->n_columns; col++) { /* Process a single record into curr_rec */
if (diff_types && col) api_get_val = gmtapi_select_get_function (API, V_obj->type[col]);
api_get_val (&(V_obj->data[col]), row, &(GMT->current.io.curr_rec[col]));
}

In the example above, the two columns have different types (GMT_DOUBLE and GMT_LONG), thus diff_types is true. At L4018, api_get_val is set to gmtapi_get_val_double.

  • row=0, col=0, L4023 isn't executed, api_get_val=gmtapi_get_val_double
  • row=0, col=1, L4023 is executed, api_get_val=gmtapi_get_val_long
  • row=1, col=0, L4023 isn't executed, api_get_val=gmtapi_get_val_long [BUG HERE]
  • row=1, col=1, L4023 is executed, api_get_val=gmtapi_get_val_long

Activity

  1. added a commit that references this issue on May 14, 2020
    7764daf
  2. added a commit that references this issue on May 14, 2020
    1eab537
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions