@@ -162,14 +162,14 @@ def _to_numpy(data: Any) -> np.ndarray:
162
162
"date64[ms][pyarrow]" : np .datetime64 ,
163
163
}
164
164
165
- # pandas nullable dtypes and pyarrow types were converted to np.object_ dtype
166
- # before, and are converted to suitable numpy dtypes since pandas 2.2.
167
- # Refer to the following link for details:
168
- # https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#to-numpy-for-numpy-nullable-and-arrow-types-converts-to-suitable-numpy-dtype
165
+ # pandas numeric dtypes were converted to np.object_ dtype prior pandas 2.2, and are
166
+ # converted to suitable numpy dtypes since pandas 2.2. Refer to the following link
167
+ # for details: https://pandas.pydata.org/docs/whatsnew/v2.2.0.html#to-numpy-for-numpy-nullable-and-arrow-types-converts-to-suitable-numpy-dtype
169
168
# Here are the workarounds for pandas < 2.2.
170
169
# Following SPEC 0, pandas 2.1 should be dropped in 2025 Q3, so it's likely we can
171
170
# remove the workaround in PyGMT v0.17.0.
172
171
if Version (pd .__version__ ) < Version ("2.2" ):
172
+ # Specify mapping from pandas nullable dtypes to suitable numpy dtypes
173
173
dtypes .update (
174
174
{
175
175
"Int8" : np .int8 ,
@@ -184,9 +184,10 @@ def _to_numpy(data: Any) -> np.ndarray:
184
184
"Float64" : np .float64 ,
185
185
}
186
186
)
187
- if hasattr (data , "isna" ) and data .isna ().any ():
188
- # Integer dtypes with missing values are cast to NumPy float dtypes and NaN
189
- # is used as missing value indicator.
187
+ # For pandas.Index/pandas.Series, pandas/pyarrow integer dtypes with missing
188
+ # values should be cast to NumPy float dtypes and NaN is used as missing value
189
+ # indicator.
190
+ if getattr (data , "hasnans" , False ): # pandas.Index/pandas.Series has 'hasnans'
190
191
dtype = np .float64 if data .dtype .kind in "iu" else data .dtype .numpy_dtype
191
192
data = data .to_numpy (na_value = np .nan ).astype (dtype = dtype )
192
193
0 commit comments