Closed willschlitzer closed 3 years ago
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 https://github.com/GenericMappingTools/pygmt/pull/1345#issuecomment-870091881) - 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.
The documentation for
grdtrack
states that an argument fornewcolname
is required if the argument forpoints
is a DataFrame. However, aGMTInvalidInput
error requiring an argument fornewcolname
is raised ifpoints
is a numpy array or a list as well.Full code that generated the error Import statement
Points as a numpy array
Points as a list
Full error message
The error is raised in lines 251-252 in
grdtrack.py
It looks like
data_kind()
won't distinguish between a DataFrame and a numpy array and returns "matrix" in both instances. Shouldnewcolname
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 thatpoints
is a DataFrame?