@@ -380,6 +380,82 @@ def test_subplots_timeseries(self):
380380 self ._check_ticks_props (ax , xlabelsize = 7 , xrot = 45 ,
381381 ylabelsize = 7 )
382382
383+ def test_subplots_timeseries_y_axis (self ):
384+ # GH16953
385+ data = {"numeric" : np .array ([1 , 2 , 5 ]),
386+ "timedelta" : [pd .Timedelta (- 10 , unit = "s" ),
387+ pd .Timedelta (10 , unit = "m" ),
388+ pd .Timedelta (10 , unit = "h" )],
389+ "datetime_no_tz" : [pd .to_datetime ("2017-08-01 00:00:00" ),
390+ pd .to_datetime ("2017-08-01 02:00:00" ),
391+ pd .to_datetime ("2017-08-02 00:00:00" )],
392+ "datetime_all_tz" : [pd .to_datetime ("2017-08-01 00:00:00" ,
393+ utc = True ),
394+ pd .to_datetime ("2017-08-01 02:00:00" ,
395+ utc = True ),
396+ pd .to_datetime ("2017-08-02 00:00:00" ,
397+ utc = True )],
398+ "text" : ["This" , "should" , "fail" ]}
399+ testdata = DataFrame (data )
400+
401+ ax_numeric = testdata .plot (y = "numeric" )
402+ assert (ax_numeric .get_lines ()[0 ].get_data ()[1 ] ==
403+ testdata ["numeric" ].values ).all ()
404+ ax_timedelta = testdata .plot (y = "timedelta" )
405+ assert (ax_timedelta .get_lines ()[0 ].get_data ()[1 ] ==
406+ testdata ["timedelta" ].values ).all ()
407+ ax_datetime_no_tz = testdata .plot (y = "datetime_no_tz" )
408+ assert (ax_datetime_no_tz .get_lines ()[0 ].get_data ()[1 ] ==
409+ testdata ["datetime_no_tz" ].values ).all ()
410+ ax_datetime_all_tz = testdata .plot (y = "datetime_all_tz" )
411+ assert (ax_datetime_all_tz .get_lines ()[0 ].get_data ()[1 ] ==
412+ testdata ["datetime_all_tz" ].values ).all ()
413+ with pytest .raises (TypeError ):
414+ testdata .plot (y = "text" )
415+
416+ @pytest .mark .xfail (reason = 'not support for period, categorical, '
417+ 'datetime_mixed_tz' )
418+ def test_subplots_timeseries_y_axis_not_supported (self ):
419+ """
420+ This test will fail for:
421+ period:
422+ since period isn't yet implemented in ``select_dtypes``
423+ and because it will need a custom value converter +
424+ tick formater (as was done for x-axis plots)
425+
426+ categorical:
427+ because it will need a custom value converter +
428+ tick formater (also doesn't work for x-axis, as of now)
429+
430+ datetime_mixed_tz:
431+ because of the way how pandas handels ``Series`` of
432+ ``datetime`` objects with different timezone,
433+ generally converting ``datetime`` objects in a tz-aware
434+ form could help with this problem
435+ """
436+ data = {"numeric" : np .array ([1 , 2 , 5 ]),
437+ "period" : [pd .Period ('2017-08-01 00:00:00' , freq = 'H' ),
438+ pd .Period ('2017-08-01 02:00' , freq = 'H' ),
439+ pd .Period ('2017-08-02 00:00:00' , freq = 'H' )],
440+ "categorical" : pd .Categorical (["c" , "b" , "a" ],
441+ categories = ["a" , "b" , "c" ],
442+ ordered = False ),
443+ "datetime_mixed_tz" : [pd .to_datetime ("2017-08-01 00:00:00" ,
444+ utc = True ),
445+ pd .to_datetime ("2017-08-01 02:00:00" ),
446+ pd .to_datetime ("2017-08-02 00:00:00" )]}
447+ testdata = pd .DataFrame (data )
448+ ax_period = testdata .plot (x = "numeric" , y = "period" )
449+ assert (ax_period .get_lines ()[0 ].get_data ()[1 ] ==
450+ testdata ["period" ].values ).all ()
451+ ax_categorical = testdata .plot (x = "numeric" , y = "categorical" )
452+ assert (ax_categorical .get_lines ()[0 ].get_data ()[1 ] ==
453+ testdata ["categorical" ].values ).all ()
454+ ax_datetime_mixed_tz = testdata .plot (x = "numeric" ,
455+ y = "datetime_mixed_tz" )
456+ assert (ax_datetime_mixed_tz .get_lines ()[0 ].get_data ()[1 ] ==
457+ testdata ["datetime_mixed_tz" ].values ).all ()
458+
383459 @pytest .mark .slow
384460 def test_subplots_layout (self ):
385461 # GH 6667
0 commit comments