You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
grdtrack raises an input error when points are not a DataFrame and no column name is specified #1344
The documentation for grdtrack states that an argument for newcolname is required if the argument for points is a DataFrame. However, a GMTInvalidInput error requiring an argument for newcolname is raised if points is a numpy array or a list as well.
Full code that generated the error Import statement
GMTInvalidInput: Please pass in a str to 'newcolname'
The error is raised in lines 251-252 in grdtrack.py
ifdata_kind(points) =="matrix"andnewcolnameisNone:
raiseGMTInvalidInput("Please pass in a str to 'newcolname'")
It looks like data_kind() won't distinguish between a DataFrame and a numpy array and returns "matrix" in both instances. Should newcolname be a required parameter for all matrix-type data, since the function still returns a DataFrame if no outfile is specified, or should the error handling check to make sure that points is a DataFrame?
I think the motivation for having newcolname as required for the dataframe input and output case case was probably because two columns cannot have the same name, so it's not simple to use a default column name for the output. Since this isn't a problem when creating a dataframe from numpy inputs, I do not think it should be required for that case.
Another note regarding newcolname (originally posted in #1345 (comment)) - it should also accept a list with multiple column names for instances in which multiple grids are sampled.
@meghanrjones So are you thinking there should be a check to see if the type is not a DataFrame and then it will substitute in a default column name is it check passes?
@meghanrjones So are you thinking there should be a check to see if the type is not a DataFrame and then it will substitute in a default column name is it check passes?
I imagine that the output DataFrame column names for non-DataFrame input when newcolname is not given could be the column index, similar to the default pandas behavior for pandas.read_csv(file,header=None).
@meghanrjones So are you thinking there should be a check to see if the type is not a DataFrame and then it will substitute in a default column name is it check passes?
I imagine that the output DataFrame column names for non-DataFrame input when newcolname is not given could be the column index, similar to the default pandas behavior for pandas.read_csv(file,header=None).
Since the default argument for newcolname is None, I think the easiest solution is to change the if statement to raise GMTInvalidInput if points are a DataFrame.
Activity
maxrjones commentedon Jun 25, 2021
I think the motivation for having newcolname as required for the dataframe input and output case case was probably because two columns cannot have the same name, so it's not simple to use a default column name for the output. Since this isn't a problem when creating a dataframe from numpy inputs, I do not think it should be required for that case.
maxrjones commentedon Jun 30, 2021
Another note regarding
newcolname(originally posted in #1345 (comment)) - it should also accept a list with multiple column names for instances in which multiple grids are sampled.willschlitzer commentedon Jul 6, 2021
@meghanrjones So are you thinking there should be a check to see if the type is not a DataFrame and then it will substitute in a default column name is it check passes?
maxrjones commentedon Jul 6, 2021
I imagine that the output DataFrame column names for non-DataFrame input when newcolname is not given could be the column index, similar to the default pandas behavior for pandas.read_csv(file,header=None).
willschlitzer commentedon Jul 6, 2021
Since the default argument for
newcolnameisNone, I think the easiest solution is to change the if statement to raiseGMTInvalidInputifpointsare a DataFrame.