@@ -1333,7 +1333,7 @@ def test_quantile(data, interpolation, quantile, request):
1333
1333
1334
1334
if pa .types .is_integer (pa_dtype ) or pa .types .is_floating (pa_dtype ):
1335
1335
pass
1336
- elif pa .types .is_temporal (data ._data .type ) and interpolation in [ "lower" , "higher" ] :
1336
+ elif pa .types .is_temporal (data ._data .type ):
1337
1337
pass
1338
1338
else :
1339
1339
request .node .add_marker (
@@ -1345,6 +1345,28 @@ def test_quantile(data, interpolation, quantile, request):
1345
1345
data = data .take ([0 , 0 , 0 ])
1346
1346
ser = pd .Series (data )
1347
1347
result = ser .quantile (q = quantile , interpolation = interpolation )
1348
+
1349
+ if pa .types .is_timestamp (pa_dtype ) and interpolation not in ["lower" , "higher" ]:
1350
+ # rounding error will make the check below fail
1351
+ # (e.g. '2020-01-01 01:01:01.000001' vs '2020-01-01 01:01:01.000001024'),
1352
+ # so we'll check for now that we match the numpy analogue
1353
+ if pa_dtype .tz :
1354
+ pd_dtype = f"M8[{ pa_dtype .unit } , { pa_dtype .tz } ]"
1355
+ else :
1356
+ pd_dtype = f"M8[{ pa_dtype .unit } ]"
1357
+ ser_np = ser .astype (pd_dtype )
1358
+
1359
+ expected = ser_np .quantile (q = quantile , interpolation = interpolation )
1360
+ if quantile == 0.5 :
1361
+ if pa_dtype .unit == "us" :
1362
+ expected = expected .to_pydatetime (warn = False )
1363
+ assert result == expected
1364
+ else :
1365
+ if pa_dtype .unit == "us" :
1366
+ expected = expected .dt .floor ("us" )
1367
+ tm .assert_series_equal (result , expected .astype (data .dtype ))
1368
+ return
1369
+
1348
1370
if quantile == 0.5 :
1349
1371
assert result == data [0 ]
1350
1372
else :
0 commit comments