@@ -58,15 +58,15 @@ def _validate_data_input(
58
58
>>> _validate_data_input(
59
59
... data=pd.DataFrame(data, columns=["x", "y"]),
60
60
... required_z=True,
61
- ... kind="matrix ",
61
+ ... kind="vectors ",
62
62
... )
63
63
Traceback (most recent call last):
64
64
...
65
65
pygmt.exceptions.GMTInvalidInput: data must provide x, y, and z columns.
66
66
>>> _validate_data_input(
67
67
... data=xr.Dataset(pd.DataFrame(data, columns=["x", "y"])),
68
68
... required_z=True,
69
- ... kind="matrix ",
69
+ ... kind="vectors ",
70
70
... )
71
71
Traceback (most recent call last):
72
72
...
@@ -96,23 +96,31 @@ def _validate_data_input(
96
96
if data is None : # data is None
97
97
if x is None and y is None : # both x and y are None
98
98
if required_data : # data is not optional
99
- raise GMTInvalidInput ("No input data provided." )
99
+ msg = "No input data provided."
100
+ raise GMTInvalidInput (msg )
100
101
elif x is None or y is None : # either x or y is None
101
- raise GMTInvalidInput ("Must provide both x and y." )
102
+ msg = "Must provide both x and y."
103
+ raise GMTInvalidInput (msg )
102
104
if required_z and z is None : # both x and y are not None, now check z
103
- raise GMTInvalidInput ("Must provide x, y, and z." )
105
+ msg = "Must provide x, y, and z."
106
+ raise GMTInvalidInput (msg )
104
107
else : # data is not None
105
108
if x is not None or y is not None or z is not None :
106
- raise GMTInvalidInput ("Too much data. Use either data or x/y/z." )
107
- # For 'matrix' kind, check if data has the required z column
108
- if kind == "matrix" and required_z :
109
- if hasattr (data , "shape" ): # np.ndarray or pd.DataFrame
110
- if len (data .shape ) == 1 and data .shape [0 ] < 3 :
111
- raise GMTInvalidInput ("data must provide x, y, and z columns." )
112
- if len (data .shape ) > 1 and data .shape [1 ] < 3 :
113
- raise GMTInvalidInput ("data must provide x, y, and z columns." )
114
- if hasattr (data , "data_vars" ) and len (data .data_vars ) < 3 : # xr.Dataset
115
- raise GMTInvalidInput ("data must provide x, y, and z columns." )
109
+ msg = "Too much data. Use either data or x/y/z."
110
+ raise GMTInvalidInput (msg )
111
+ # check if data has the required z column
112
+ if required_z :
113
+ msg = "data must provide x, y, and z columns."
114
+ if kind == "matrix" and data .shape [1 ] < 3 :
115
+ raise GMTInvalidInput (msg )
116
+ if kind == "vectors" :
117
+ if hasattr (data , "shape" ) and (
118
+ (len (data .shape ) == 1 and data .shape [0 ] < 3 )
119
+ or (len (data .shape ) > 1 and data .shape [1 ] < 3 )
120
+ ): # np.ndarray or pd.DataFrame
121
+ raise GMTInvalidInput (msg )
122
+ if hasattr (data , "data_vars" ) and len (data .data_vars ) < 3 : # xr.Dataset
123
+ raise GMTInvalidInput (msg )
116
124
117
125
118
126
def _check_encoding (
0 commit comments