File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -161,17 +161,33 @@ def _to_ndarray(array: Any) -> np.ndarray:
161161 "date32[day][pyarrow]" : np .datetime64 ,
162162 "date64[ms][pyarrow]" : np .datetime64 ,
163163 }
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+ )
164184
165185 if (
166186 hasattr (array , "isna" )
167187 and array .isna ().any ()
168188 and Version (pd .__version__ ) < Version ("2.2" )
169189 ):
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 ))
175191 else :
176192 vec_dtype = str (getattr (array , "dtype" , "" ))
177193 array = np .ascontiguousarray (array , dtype = dtypes .get (vec_dtype ))
You can’t perform that action at this time.
0 commit comments