@@ -186,25 +186,57 @@ def test_interval_dtype_with_categorical(dtype):
186186 ["date32[pyarrow]" , "date32[pyarrow]" ],
187187 "date32[day][pyarrow]" ,
188188 ),
189- (
190- ["date64[pyarrow]" , "null[pyarrow]" ],
191- "date64[ms][pyarrow]" , # timestamp[ms][pyarrow]
192- ),
193189 (
194190 ["date64[pyarrow]" , "date64[pyarrow]" ],
195191 "date64[ms][pyarrow]" ,
196192 ),
197- (
198- ["date32[pyarrow]" , "date64[pyarrow]" ],
199- "date64[ms][pyarrow]" , # timestamp[ms][pyarrow]
200- ),
201193 (
202194 ["date32[pyarrow]" , "date64[pyarrow]" , "datetime64[ms]" ],
203195 "timestamp[ms][pyarrow]" ,
204196 ),
205197 ],
206198)
207199def test_pyarrow_date_dtypes (dtypes , expected ):
200+ source_dtypes = [pandas_dtype (dtype ) for dtype in dtypes ]
201+ result = find_common_type (source_dtypes )
202+ assert result == pandas_dtype (expected )
203+
204+ @pytest .mark .xfail (reason = """
205+ Finding common pyarrow dtypes relies on conversion
206+ to numpy dtypes and then back to pyarrow dtypes.
207+
208+ We have:
209+ >>> pa.from_numpy_dtype(np.dtype('datetime64[D]'))
210+ DataType(date32[day])
211+ >>> pa.from_numpy_dtype(np.dtype('datetime64[ms]'))
212+ TimestampType(timestamp[ms])
213+
214+ To fix this test, we would need to have
215+ >>> pa.from_numpy_dtype(np.dtype('datetime64[ms]'))
216+ DataType(date64[ms])
217+
218+ But date64 isn't the same as datetime64[ms]. date64
219+ is meant to represent a date (without time) only,
220+ represented in milliseconds (see
221+ https://github.com/apache/arrow/issues/15032#issuecomment-1368096718).
222+
223+ Hence, some date64-related common type computations
224+ end up becoming cast to timestamps rather than date64.
225+ """ )
226+ @pytest .mark .parametrize (
227+ "dtypes,expected" ,
228+ [
229+ (
230+ ["date64[pyarrow]" , "null[pyarrow]" ],
231+ "date64[ms][pyarrow]" ,
232+ ),
233+ (
234+ ["date32[pyarrow]" , "date64[pyarrow]" ],
235+ "date64[ms][pyarrow]" ,
236+ ),
237+ ],
238+ )
239+ def test_pyarrow_date64_dtype (dtypes , expected ):
208240 source_dtypes = [pandas_dtype (dtype ) for dtype in dtypes ]
209241 result = find_common_type (source_dtypes )
210242 print (f'{ source_dtypes } : { result } ' )
0 commit comments