-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Session.virtualfile_in: Remove the "extra_arrays" parameter #3823
base: main
Are you sure you want to change the base?
Conversation
ad6b015
to
9733c53
Compare
1ff0de4
to
df88e02
Compare
@@ -143,6 +144,15 @@ def _validate_data_input( | |||
raise GMTInvalidInput(msg) | |||
if hasattr(data, "data_vars") and len(data.data_vars) < 3: # xr.Dataset | |||
raise GMTInvalidInput(msg) | |||
if kind == "vectors" and isinstance(data, dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that, these new codes in _validate_data_input
is temporary and I plan to refactor _validate_data_input
in a separate PR.
Hopefully @weiji14 will have some time reviewing this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @seisman, super busy with work so might not be able to give this a closer review until end of March or so. But just left two comments below for now.
@@ -1794,9 +1793,6 @@ def virtualfile_in( | |||
data input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add dict
as a possible type of data
to L1790
x=None, | ||
y=None, | ||
z=None, | ||
extra_arrays=None, | ||
required_z=False, | ||
required_data=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should raise warnings when extra_arrays is used and keep backward compatibility for a few versions (maybe 4 versions).
If we're going to break compatibility of virtualfile_in
for 4 minor versions, maybe it's a good time to rethink the parameter ordering (ties in with potential changes in #3369). Would it make sense for the signature to be something like:
def virtualfile_in(
self,
check_kind=None,
required_data=True,
required_z=False,
data=None,
x=None,
y=None,
z=None,
**extra_arrays
? We could also mark some of those parameters as keyword only (https://peps.python.org/pep-0570/#keyword-only-arguments) to ensure future compatibility (i.e. prevent positional-only parameters/arguments in case we decide to change the order again).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #3836 for my thoughts on the Session.virtualfile_in
method.
As mentioned in #3836, I plan to make many refactors (likely backward-incompatible) to the |
For GMT modules that accept table inputs, the number of required columns can vary significantly. Most modules typically need between one and three columns. For instance:
histogram
module requires only one column but can optionally accept a second column for weighting.rose
module needs two columns.contour
module requires three columns.For these modules, the table input can be provided either through the
data
parameter or via thex
,y
, andz
parameters. This is why theSession.virtualfile_in
method includes parameters likedata
,x
,y
, andz
.However, some modules may require more than three columns. For example, the
plot
module can accept over 10 columns depending on the options specified. To accommodate these cases, theSession.virtualfile_in
method currently includes anextra_arrays
parameter, which is a list of additional vectors beyondx
,y
, andz
. This requires users to define a list and append extra columns to it.This PR proposes removing the
extra_arrays
parameter. Instead of passingx
,y
,z
, andextra_arrays
, we can simplify the process by using a dictionary of vectors, i.e., when data kind is"empty"
, create a dict like below and pass it directly toSession.virtualfile_in
:The dict-like data can be thought as a lightweight pandas.DataFrame object, and it will be recognized as the
"vector"
kind indata_kind
andSession.virtualfile_in
. This approach enhances flexibility and usability, especially for modules requiring a larger number of input columns.Changes in this PR:
extra_arrays
parameters fromSession.virtualfile_in
. Thex
/y
/z
parameters are still kept since for some modules passingx
/y
/z
vectors is easier that passing a dict ofx
/y
/z
Figure.plot
/Figure.plot3d
/Figure.text
to get rid ofextra_arrays
_validate_data_input
, add extra checks to ensure that the dict values are not None. Please note that I plan to refactor/simplify the_validate_data_input
function in a separate PR (i.e., Refactor _validate_data_input to simplify the codes #3818)Figure.plot3d
to ensure that an error is raise when z is not provided.Strictly speaking, this is a breaking change for users who call
Session.virtualfile_in
, so let me know if you think we should raise warnings whenextra_arrays
is used and keep backward compatibility for a few versions (maybe 4 versions).