@@ -157,21 +157,37 @@ def _to_ndarray(array: Any) -> np.ndarray:
157
157
The C contiguous numpy array.
158
158
"""
159
159
# A dictionary mapping unsupported dtypes to the expected numpy dtype.
160
- dtypes = {
160
+ dtypes : dict [ str , type ] = {
161
161
"date32[day][pyarrow]" : np .datetime64 ,
162
162
"date64[ms][pyarrow]" : np .datetime64 ,
163
163
}
164
+ # pandas nullable types and pyarrow types were converted to object dtype prior to
165
+ # pandas 2.2, and these dtypes are now converted to suitable numpy dtypes.
166
+ # https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#to-numpy-for-numpy-nullable-and-arrow-types-converts-to-suitable-numpy-dtype
167
+ # Following SPEC 0, pandas 2.1 will be dropped in 2025 Q3, so it's likely we can
168
+ # remove the workaround in PyGMT v0.17.0.
169
+ if Version (pd .__version__ ) < Version ("2.2" ):
170
+ dtypes .update (
171
+ {
172
+ "Int8" : np .int8 ,
173
+ "Int16" : np .int16 ,
174
+ "Int32" : np .int32 ,
175
+ "Int64" : np .int64 ,
176
+ "UInt8" : np .uint8 ,
177
+ "UInt16" : np .uint16 ,
178
+ "UInt32" : np .uint32 ,
179
+ "UInt64" : np .uint64 ,
180
+ "Float32" : np .float32 ,
181
+ "Float64" : np .float64 ,
182
+ }
183
+ )
164
184
165
185
if (
166
186
hasattr (array , "isna" )
167
187
and array .isna ().any ()
168
188
and Version (pd .__version__ ) < Version ("2.2" )
169
189
):
170
- # Workaround for dealing with pd.NA with pandas < 2.2.
171
- # Bug report at: https://github.com/GenericMappingTools/pygmt/issues/2844
172
- # Following SPEC0, pandas 2.1 will be dropped in 2025 Q3, so it's likely
173
- # we can remove the workaround in PyGMT v0.17.0.
174
- array = np .ascontiguousarray (array .astype (float ))
190
+ array = np .ascontiguousarray (array .astype (np .float64 ))
175
191
else :
176
192
vec_dtype = str (getattr (array , "dtype" , "" ))
177
193
array = np .ascontiguousarray (array , dtype = dtypes .get (vec_dtype ))
0 commit comments