100100 "because the necessary `__from_arrow__` attribute is missing."
101101)
102102
103+ _RANGE_PYARROW_WARNING = (
104+ "Unable to represent RANGE schema as struct using pandas ArrowDtype. Using "
105+ "`object` instead. To use ArrowDtype, use pandas >= 1.5 and "
106+ "pyarrow >= 10.0.1."
107+ )
108+
103109# How many of the total rows need to be downloaded already for us to skip
104110# calling the BQ Storage API?
105111ALMOST_COMPLETELY_CACHED_RATIO = 0.333
@@ -2279,26 +2285,18 @@ def to_dataframe(
22792285 time_dtype = db_dtypes .TimeDtype ()
22802286
22812287 if range_date_dtype is DefaultPandasDTypes .RANGE_DATE_DTYPE :
2282- try :
2288+ if _versions_helpers . SUPPORTS_RANGE_PYARROW :
22832289 range_date_dtype = pandas .ArrowDtype (
22842290 pyarrow .struct (
22852291 [("start" , pyarrow .date32 ()), ("end" , pyarrow .date32 ())]
22862292 )
22872293 )
2288- except AttributeError :
2289- # pandas.ArrowDtype was introduced in pandas 1.5, but python 3.7
2290- # only supports upto pandas 1.3. If pandas.ArrowDtype is not
2291- # present, we raise a warning and set range_date_dtype to None.
2292- msg = (
2293- "Unable to find class ArrowDtype in pandas, setting "
2294- "range_date_dtype to be None. To use ArrowDtype, please "
2295- "use pandas >= 1.5 and python >= 3.8."
2296- )
2297- warnings .warn (msg )
2294+ else :
2295+ warnings .warn (_RANGE_PYARROW_WARNING )
22982296 range_date_dtype = None
22992297
23002298 if range_datetime_dtype is DefaultPandasDTypes .RANGE_DATETIME_DTYPE :
2301- try :
2299+ if _versions_helpers . SUPPORTS_RANGE_PYARROW :
23022300 range_datetime_dtype = pandas .ArrowDtype (
23032301 pyarrow .struct (
23042302 [
@@ -2307,20 +2305,12 @@ def to_dataframe(
23072305 ]
23082306 )
23092307 )
2310- except AttributeError :
2311- # pandas.ArrowDtype was introduced in pandas 1.5, but python 3.7
2312- # only supports upto pandas 1.3. If pandas.ArrowDtype is not
2313- # present, we raise a warning and set range_datetime_dtype to None.
2314- msg = (
2315- "Unable to find class ArrowDtype in pandas, setting "
2316- "range_datetime_dtype to be None. To use ArrowDtype, "
2317- "please use pandas >= 1.5 and python >= 3.8."
2318- )
2319- warnings .warn (msg )
2308+ else :
2309+ warnings .warn (_RANGE_PYARROW_WARNING )
23202310 range_datetime_dtype = None
23212311
23222312 if range_timestamp_dtype is DefaultPandasDTypes .RANGE_TIMESTAMP_DTYPE :
2323- try :
2313+ if _versions_helpers . SUPPORTS_RANGE_PYARROW :
23242314 range_timestamp_dtype = pandas .ArrowDtype (
23252315 pyarrow .struct (
23262316 [
@@ -2329,16 +2319,8 @@ def to_dataframe(
23292319 ]
23302320 )
23312321 )
2332- except AttributeError :
2333- # pandas.ArrowDtype was introduced in pandas 1.5, but python 3.7
2334- # only supports upto pandas 1.3. If pandas.ArrowDtype is not
2335- # present, we raise a warning and set range_timestamp_dtype to None.
2336- msg = (
2337- "Unable to find class ArrowDtype in pandas, setting "
2338- "range_timestamp_dtype to be None. To use ArrowDtype, "
2339- "please use pandas >= 1.5 and python >= 3.8."
2340- )
2341- warnings .warn (msg )
2322+ else :
2323+ warnings .warn (_RANGE_PYARROW_WARNING )
23422324 range_timestamp_dtype = None
23432325
23442326 if bool_dtype is not None and not hasattr (bool_dtype , "__from_arrow__" ):
0 commit comments