-
Notifications
You must be signed in to change notification settings - Fork 234
Session.virtualfile_in: Deprecate the parameter 'extra_arrays'. Prepare and pass a dictionary of arrays instead (will be removed in v0.20.0) #3823
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
Conversation
ad6b015 to
9733c53
Compare
1ff0de4 to
df88e02
Compare
| 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.
| 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 |
This was done in 5330d0a. |
Co-authored-by: Wei Ji <[email protected]>
Co-authored-by: Wei Ji <[email protected]>
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:
histogrammodule requires only one column but can optionally accept a second column for weighting.rosemodule needs two columns.contourmodule requires three columns.For these modules, the table input can be provided either through the
dataparameter or via thex,y, andzparameters. This is why theSession.virtualfile_inmethod includes parameters likedata,x,y, andz.However, some modules may require more than three columns. For example, the
plotmodule can accept over 10 columns depending on the options specified. To accommodate these cases, theSession.virtualfile_inmethod currently includes anextra_arraysparameter, 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_arraysparameter. 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_kindandSession.virtualfile_in. This approach enhances flexibility and usability, especially for modules requiring a larger number of input columns.Changes in this PR:
extra_arraysparameters fromSession.virtualfile_in. Thex/y/zparameters are still kept since for some modules passingx/y/zvectors is easier that passing a dict ofx/y/zFigure.plot/Figure.plot3d/Figure.textto 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_inputfunction in a separate PR (i.e., Refactor _validate_data_input to simplify the codes #3818)Figure.plot3dto 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_arraysis used and keep backward compatibility for a few versions (maybe 4 versions).