@@ -280,9 +280,13 @@ def test_quantile_datetime(self):
280
280
tm .assert_frame_equal (result , expected )
281
281
282
282
# empty when numeric_only=True
283
- # FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
284
- # result = df[['a', 'c']].quantile(.5)
285
- # result = df[['a', 'c']].quantile([.5])
283
+ result = df [["a" , "c" ]].quantile (0.5 )
284
+ expected = Series ([], index = [], dtype = np .float64 , name = 0.5 )
285
+ tm .assert_series_equal (result , expected )
286
+
287
+ result = df [["a" , "c" ]].quantile ([0.5 ])
288
+ expected = DataFrame (index = [0.5 ])
289
+ tm .assert_frame_equal (result , expected )
286
290
287
291
def test_quantile_invalid (self , datetime_frame ):
288
292
msg = "percentiles should all be in the interval \\ [0, 1\\ ]"
@@ -481,7 +485,7 @@ def test_quantile_nat(self):
481
485
)
482
486
tm .assert_frame_equal (res , exp )
483
487
484
- def test_quantile_empty_no_rows (self ):
488
+ def test_quantile_empty_no_rows_floats (self ):
485
489
486
490
# floats
487
491
df = DataFrame (columns = ["a" , "b" ], dtype = "float64" )
@@ -494,21 +498,43 @@ def test_quantile_empty_no_rows(self):
494
498
exp = DataFrame ([[np .nan , np .nan ]], columns = ["a" , "b" ], index = [0.5 ])
495
499
tm .assert_frame_equal (res , exp )
496
500
497
- # FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
498
- # res = df.quantile(0.5, axis=1)
499
- # res = df.quantile([0.5], axis=1)
501
+ res = df .quantile (0.5 , axis = 1 )
502
+ exp = Series ([], index = [], dtype = "float64" , name = 0.5 )
503
+ tm .assert_series_equal (res , exp )
504
+
505
+ res = df .quantile ([0.5 ], axis = 1 )
506
+ exp = DataFrame (columns = [], index = [0.5 ])
507
+ tm .assert_frame_equal (res , exp )
500
508
509
+ def test_quantile_empty_no_rows_ints (self ):
501
510
# ints
502
511
df = DataFrame (columns = ["a" , "b" ], dtype = "int64" )
503
512
504
- # FIXME (gives empty frame in 0.18.1, broken in 0.19.0)
505
- # res = df.quantile(0.5)
513
+ res = df .quantile (0.5 )
514
+ exp = Series ([np .nan , np .nan ], index = ["a" , "b" ], name = 0.5 )
515
+ tm .assert_series_equal (res , exp )
506
516
517
+ def test_quantile_empty_no_rows_dt64 (self ):
507
518
# datetimes
508
519
df = DataFrame (columns = ["a" , "b" ], dtype = "datetime64[ns]" )
509
520
510
- # FIXME (gives NaNs instead of NaT in 0.18.1 or 0.19.0)
511
- # res = df.quantile(0.5, numeric_only=False)
521
+ res = df .quantile (0.5 , numeric_only = False )
522
+ exp = Series (
523
+ [pd .NaT , pd .NaT ], index = ["a" , "b" ], dtype = "datetime64[ns]" , name = 0.5
524
+ )
525
+ tm .assert_series_equal (res , exp )
526
+
527
+ # Mixed dt64/dt64tz
528
+ df ["a" ] = df ["a" ].dt .tz_localize ("US/Central" )
529
+ res = df .quantile (0.5 , numeric_only = False )
530
+ exp = exp .astype (object )
531
+ tm .assert_series_equal (res , exp )
532
+
533
+ # both dt64tz
534
+ df ["b" ] = df ["b" ].dt .tz_localize ("US/Central" )
535
+ res = df .quantile (0.5 , numeric_only = False )
536
+ exp = exp .astype (df ["b" ].dtype )
537
+ tm .assert_series_equal (res , exp )
512
538
513
539
def test_quantile_empty_no_columns (self ):
514
540
# GH#23925 _get_numeric_data may drop all columns
0 commit comments