@@ -2274,26 +2274,31 @@ def name(self) -> str: # type: ignore[override]
22742274
22752275 @cache_readonly
22762276 def numpy_dtype (self ) -> np .dtype :
2277- """Return an instance of the related numpy dtype"""
2278- if pa .types .is_timestamp (self .pyarrow_dtype ):
2279- if self .pyarrow_dtype .tz is not None :
2280- # Handle timezone-aware timestamps
2281- return np .dtype (f"datetime64[{ self .pyarrow_dtype .unit } ]" )
2277+ """Return an instance of the related numpy dtype."""
2278+ if pa .types .is_timestamp (self .pyarrow_dtype ):
2279+ if self .pyarrow_dtype .tz is not None :
22822280 return np .dtype (f"datetime64[{ self .pyarrow_dtype .unit } ]" )
2283- if pa .types .is_duration (self .pyarrow_dtype ):
2284- return np .dtype (f"timedelta64[{ self .pyarrow_dtype .unit } ]" )
2285- if pa .types .is_string (self .pyarrow_dtype ) or pa .types .is_large_string (
2286- self .pyarrow_dtype
2287- ):
2288- return np .dtype (str )
2289- try :
2290- np_dtype = self .pyarrow_dtype .to_pandas_dtype ()
2291- if isinstance (np_dtype , DatetimeTZDtype ):
2292- # Convert timezone-aware to naive datetime64
2293- return np .dtype (f"datetime64[{ np_dtype .unit } ]" )
2294- return np .dtype (np_dtype )
2295- except (NotImplementedError , TypeError ):
2296- return np .dtype (object )
2281+ return np .dtype (f"datetime64[{ self .pyarrow_dtype .unit } ]" )
2282+ if pa .types .is_duration (self .pyarrow_dtype ):
2283+ return np .dtype (f"timedelta64[{ self .pyarrow_dtype .unit } ]" )
2284+ if pa .types .is_string (self .pyarrow_dtype ) or pa .types .is_large_string (
2285+ self .pyarrow_dtype
2286+ ):
2287+ return np .dtype (str )
2288+ try :
2289+ np_dtype = self .pyarrow_dtype .to_pandas_dtype ()
2290+
2291+ if isinstance (np_dtype , object ):
2292+ if hasattr (np_dtype , "categories" ) and isinstance (np_dtype .categories , pd .IntervalIndex ):
2293+ return np .dtype (object )
2294+
2295+ if isinstance (np_dtype , DatetimeTZDtype ):
2296+ return np .dtype (f"datetime64[{ np_dtype .unit } ]" )
2297+
2298+ return np .dtype (np_dtype )
2299+ except (NotImplementedError , TypeError ):
2300+ return np .dtype (object )
2301+
22972302
22982303
22992304 @cache_readonly
0 commit comments