File tree 2 files changed +17
-7
lines changed
2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -137,15 +137,17 @@ def to_pyarrow_type(
137
137
Convert dtype to a pyarrow type instance.
138
138
"""
139
139
if isinstance (dtype , ArrowDtype ):
140
- pa_dtype = dtype .pyarrow_dtype
140
+ return dtype .pyarrow_dtype
141
141
elif isinstance (dtype , pa .DataType ):
142
- pa_dtype = dtype
142
+ return dtype
143
143
elif dtype :
144
- # Accepts python types too
145
- pa_dtype = pa .from_numpy_dtype (dtype )
146
- else :
147
- pa_dtype = None
148
- return pa_dtype
144
+ try :
145
+ # Accepts python types too
146
+ # Doesn't handle all numpy types
147
+ return pa .from_numpy_dtype (dtype )
148
+ except pa .ArrowNotImplementedError :
149
+ pass
150
+ return None
149
151
150
152
151
153
class ArrowExtensionArray (OpsMixin , ExtensionArray ):
Original file line number Diff line number Diff line change @@ -120,3 +120,11 @@ def test_pyarrow_dtype_backend_from_pandas_nullable(self):
120
120
}
121
121
)
122
122
tm .assert_frame_equal (result , expected )
123
+
124
+ def test_pyarrow_dtype_empty_object (self ):
125
+ # GH 50970
126
+ pytest .importorskip ("pyarrow" )
127
+ expected = pd .DataFrame (columns = [0 ])
128
+ with pd .option_context ("mode.dtype_backend" , "pyarrow" ):
129
+ result = expected .convert_dtypes ()
130
+ tm .assert_frame_equal (result , expected )
You can’t perform that action at this time.
0 commit comments