
    WhL                        d Z ddlmZ ddlmZmZ ddlZddlZddl	m
Z
 ddlmc mZ ddlmZ ddlZddlmZ ddlmZ erddlmZ ej         G d	 d
                      ZddZd Zd ZdS )zF
Module consolidating common testing functions for checking plotting.
    )annotations)TYPE_CHECKINGSequenceN)cache_readonly)is_list_like)SeriesAxesc                      e Zd ZdZd Zd Zed             Zed             Zd$dZ	d$d	Z
d
 Zd%dZ	 d%d&dZd Z	 d'dZd Z	 d(dZd)dZd'dZd Zd Zd*dZ	 d$dZi fdZd+d!Zd" Zd# ZdS ),TestPlotBasezE
    This is a common base class used for various plotting tests
    c                6    dd l }|                                 d S Nr   )
matplotlib
rcdefaults)selfmpls     b/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/pandas/tests/plotting/common.pysetup_methodzTestPlotBase.setup_method"   s$            c                ,    t          j                     d S N)tmclose)r   s    r   teardown_methodzTestPlotBase.teardown_method'   s    





r   c                    dd l m} |S r   )matplotlib.pyplotpyplot)r   plts     r   r   zTestPlotBase.plt*   s    ''''''
r   c                    dd l m} |j        S r   )matplotlib.colorscolorscolorConverter)r   r!   s     r   colorconverterzTestPlotBase.colorconverter0   s    ******$$r   NTc                2   |r|t          d          |                     |          }|D ]k}|rQ|                                J |                     |                                                                |           U|                                J ldS )aQ  
        Check each axes has expected legend labels

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        labels : list-like
            expected legend labels
        visible : bool
            expected legend visibility. labels are checked only when visible is
            True
        Nz-labels must be specified when visible is True)
ValueError_flatten_visible
get_legend_check_text_labels	get_texts)r   axeslabelsvisibleaxs        r   _check_legend_labelsz!TestPlotBase._check_legend_labels6   s      	NLMMM$$T** 	/ 	/B /}}222''(A(A(C(CVLLLL}}....	/ 	/r   c                    |r|t          d          |r-|                                \  }}d |D             }||k    sJ dS |                                J dS )aB  
        Check ax has expected legend markers

        Parameters
        ----------
        ax : matplotlib Axes object
        expected_markers : list-like
            expected legend markers
        visible : bool
            expected legend visibility. labels are checked only when visible is
            True
        Nz.Markers must be specified when visible is Truec                6    g | ]}|                                 S  )
get_marker).0handles     r   
<listcomp>z5TestPlotBase._check_legend_marker.<locals>.<listcomp>^   s$    AAAvv((**AAAr   )r%   get_legend_handles_labelsr'   )r   r-   expected_markersr,   handles_markerss          r   _check_legend_markerz!TestPlotBase._check_legend_markerM   s      	O(0MNNN 	+5577JGQAAAAAG.......==??*****r   c                f   |                                 }|                                 }t          |          t          |          k    sJ t          ||          D ]B\  }}|                                }|                                }t	          j        ||           Ct	          j                     dS )z
        Check each axes has identical lines

        Parameters
        ----------
        xp : matplotlib Axes object
        rs : matplotlib Axes object
        N)	get_lineslenzip
get_xydatar   assert_almost_equalr   )	r   xprsxp_linesrs_linesxplrslxpdatarsdatas	            r   _check_datazTestPlotBase._check_datac   s     <<>><<>>8}}H----Hh// 	3 	3HC^^%%F^^%%F"662222





r   c                    ddl m} t          ||          st          |          s|g}|D ]}|                                |k    sJ dS )a   
        Check each artist is visible or not

        Parameters
        ----------
        collections : matplotlib Artist or its list-like
            target Artist or its list or collection
        visible : bool
            expected visibility
        r   )
CollectionN)matplotlib.collectionsrL   
isinstancer   get_visible)r   collectionsr,   rL   patchs        r   _check_visiblezTestPlotBase._check_visiblew   sw     	655555+z22 	(<;T;T 	(&-K  	2 	2E$$&&'11111	2 	2r   r*   Axes | Sequence[Axes]filledboolreturnNonec                h    |                      |          }|D ]}|j        D ]}|j        |k    sJ dS )z
        Check for each artist whether it is filled or not

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        filled : bool
            expected filling
        N)r&   patchesfill)r   r*   rT   r-   rQ   s        r   _check_patches_all_filledz&TestPlotBase._check_patches_all_filled   s\     $$T** 	, 	,B , ,zV+++++,	, 	,r   c                    |                                 }t          t          ||                    fd|j        D             S )Nc                     g | ]
}|         S r1   r1   )r3   vmappeds     r   r5   z3TestPlotBase._get_colors_mapped.<locals>.<listcomp>   s    111aq	111r   )uniquedictr?   values)r   seriesr!   r`   r_   s       @r   _get_colors_mappedzTestPlotBase._get_colors_mapped   sE     c&&))**11116=1111r   c                2   ddl m}m}m} ddlm} | j        }	||-|                     ||          }|dt          |                   }t          |          t          |          k    sJ t          ||          D ]\  }
}t          |
|          r*|
                                }|	                    |          }nNt          |
||f          r(t          |
                                d                   }n|
                                }|	                    |          }||k    sJ ||-|                     ||          }|dt          |                   }t          |          t          |          k    sJ t          ||          D ]\  }
}t          |
|          r|
                                d         }n|
                                }t          |t           j                  rt          |          }|	                    |          }||k    sJ dS dS )a3  
        Check each artist has expected line colors and face colors

        Parameters
        ----------
        collections : list-like
            list or collection of target artist
        linecolors : list-like which has the same length as collections
            list of expected line colors
        facecolors : list-like which has the same length as collections
            list of expected face colors
        mapping : Series
            Series used for color grouping key
            used for andrew_curves, parallel_coordinates, radviz test
        r   )rL   LineCollectionPolyCollection)Line2DN)rM   rL   rf   rg   matplotlib.linesrh   r#   rd   r>   r?   rN   	get_colorto_rgbatupleget_edgecolorget_facecolornpndarray)r   rP   
linecolors
facecolorsmappingrL   rf   rg   rh   convrQ   colorresultexpecteds                 r   _check_colorszTestPlotBase._check_colors   sl   $	
 	
 	
 	
 	
 	
 	
 	
 	
 	

 	,+++++"!"!44WjII
'(:#k*:*:(:;
{##s:6666 #K < < * *ueV,, 3"__..F!\\&11FF'GHH 3"5#6#6#8#8#;<<FF"0022F<<..)))))!"!44WjII
'(:#k*:*:(:;
{##s:6666 #K < < * *ueZ00 3"002215FF"0022Ffbj11 +"6]]F<<..)))))% "!* *r   c                    t          |          s|                                |k    sJ dS d |D             }t          |          t          |          k    sJ t          ||          D ]\  }}||k    sJ dS )a.  
        Check each text has expected labels

        Parameters
        ----------
        texts : matplotlib Text object, or its list-like
            target text, or its list
        expected : str or list-like which has the same length as texts
            expected text label, or its list
        c                6    g | ]}|                                 S r1   )get_text)r3   ts     r   r5   z3TestPlotBase._check_text_labels.<locals>.<listcomp>   s     222qajjll222r   N)r   r{   r>   r?   )r   textsrw   r+   labeles         r   r(   zTestPlotBase._check_text_labels   s     E"" 	">>##x//////22E222Fv;;#h--////11 " "qzzzzz" "r   c                R   ddl m} |                     |          }|D ]}||t          |j                                        |          r|                                }n+|                                |                    d          z   }|D ]T}	|'t          j        |		                                |           |'t          j        |	
                                |           U||t          |j                                        |          r|                                }n+|                                |                    d          z   }|D ]T}	|'t          j        |		                                |           |'t          j        |	
                                |           UdS )a  
        Check each axes has expected tick properties

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        xlabelsize : number
            expected xticks font size
        xrot : number
            expected xticks rotation
        ylabelsize : number
            expected yticks font size
        yrot : number
            expected yticks rotation
        r   )NullFormatterNT)minor)matplotlib.tickerr   r&   rN   xaxisget_minor_formatterget_xticklabelsr   rA   get_fontsizeget_rotationyaxisget_yticklabels)
r   r*   
xlabelsizexrot
ylabelsizeyrotr   r-   r+   r~   s
             r   _check_ticks_propszTestPlotBase._check_ticks_props   s   $ 	433333$$T** 	K 	KB%)9bh::<<mLL S  //11FF//11B4F4FT4F4R4RRF# K KE!-.u/A/A/C/CZPPP'.u/A/A/C/CTJJJ%)9bh::<<mLL S//11FF//11B4F4FT4F4R4RRF# K KE!-.u/A/A/C/CZPPP'.u/A/A/C/CTJJJ3	K 	Kr   linearc                    |                      |          }|D ]@}|j                                        |k    sJ |j                                        |k    sJ AdS )a  
        Check each axes has expected scales

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        xaxis : {'linear', 'log'}
            expected xaxis scale
        yaxis : {'linear', 'log'}
            expected yaxis scale
        N)r&   r   	get_scaler   )r   r*   r   r   r-   s        r   _check_ax_scaleszTestPlotBase._check_ax_scales(  sq     $$T** 	1 	1B8%%''500008%%''500000	1 	1r   c                   ddl m} |d}|                     |          }|At          |          |k    sJ |D ])}t          |                                          dk    sJ *|&|                      ||                    }||k    sJ t          j        |d         j        	                                t          j        |t          j                             dS )a  
        Check expected number of axes is drawn in expected layout

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        axes_num : number
            expected number of axes. Unnecessary axes should be set to
            invisible.
        layout : tuple
            expected layout, (expected number of rows , columns)
        figsize : tuple
            expected figsize. default is matplotlib default
        r   flatten_axesN)g@g333333@)dtype)!pandas.plotting._matplotlib.toolsr   r&   r>   get_children_get_axes_layoutr   assert_numpy_array_equalfigureget_size_inchesro   arrayfloat64)	r   r*   axes_numlayoutfigsizer   visible_axesr-   rv   s	            r   _check_axes_shapezTestPlotBase._check_axes_shape9  s    	CBBBBB? G,,T22|$$0000" 2 22??,,--11111**<<+=+=>>FV####
#O"2244HWBJ///	
 	
 	
 	
 	
r   c                P   t                      }t                      }|D ]j}|                                                                }|                    |d         d                    |                    |d         d                    kt	          |          t	          |          fS )Nr      )setget_position
get_pointsaddr>   )r   r*   x_sety_setr-   pointss         r   r   zTestPlotBase._get_axes_layout]  s     	$ 	$B__&&1133FIIfQil###IIfQil####E

CJJ''r   c                @    ddl m}  ||          }d |D             }|S )z
        Flatten axes, and filter only visible

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like

        r   r   c                :    g | ]}|                                 |S r1   )rO   )r3   r-   s     r   r5   z1TestPlotBase._flatten_visible.<locals>.<listcomp>s  s'    666rR^^%5%56666r   )r   r   )r   r*   r   s      r   r&   zTestPlotBase._flatten_visibleg  s>     	CBBBBB|D!!66T666r   r   c                    |                      |          }|D ]R}|j        }d}d}|D ]2}t          |dd          }	t          |dd          }
|	r|dz  }|
r|dz  }3||k    sJ ||k    sJ SdS )a  
        Check axes has expected number of errorbars

        Parameters
        ----------
        axes : matplotlib Axes object, or its list-like
        xerr : number
            expected number of x errorbar
        yerr : number
            expected number of y errorbar
        r   has_xerrFhas_yerrr   N)r&   
containersgetattr)r   r*   xerryerrr-   r   
xerr_count
yerr_countcr   r   s              r   _check_has_errorbarsz!TestPlotBase._check_has_errorbarsv  s     $$T** 	& 	&BJJJ $ $"1j%88"1j%88 $!OJ $!OJ:%%%%:%%%%%	& 	&r   c                   ddl m} t          |t          d}|Y|d}t	          |||                   sJ |dk    r3t	          |j        |          sJ t	          |j        t                    sJ dS dS |,|                     |          D ]}t	          ||          sJ dS t	          |t                    sJ t          |
                                          t          |          k    sJ |                                D ]\  }}	t	          |	||                   sJ |dk    r|r|	                                |k    sJ @|dk    rU|r|	j                                        |k    sJ t	          |	j        |          sJ t	          |	j        t                    sJ |dk    r2|	d         d         }
|
j        }|r|                                |k    sJ t          dS )	at  
        Check box returned type is correct

        Parameters
        ----------
        returned : object to be tested, returned from boxplot
        return_type : str
            return_type passed to boxplot
        expected_keys : list-like, optional
            group labels in subplot case. If not passed,
            the function checks assuming boxplot uses single ax
        check_ax_title : bool
            Whether to check the ax.title is the same as expected_key
            Intended to be checked by calling from ``boxplot``.
            Normal ``plot`` doesn't attach ``ax.title``, it must be disabled.
        r   r	   )ra   r*   bothNra   r   r*   medians)matplotlib.axesr
   ra   rl   rN   r-   linesr&   r   sortedkeysitems	get_titler*   AssertionError)r   returnedreturn_typeexpected_keyscheck_ax_titler
   typesrkeyvalueliner*   s               r   _check_box_return_typez#TestPlotBase._check_box_return_type  s=   & 	)(((((tU;; "$hk(:;;;;;f$$!(+t44444!(.$77777 %$77 "..x88 / /A%a......h/////(--//**f].C.CCCCC&nn.. ) )
U!%{);<<<<<&((% 8$00C7777 F**% ;$x1133s::::%eh55555%ek4888888 F** +A.D9D% 7#~~//36666((#) )r   c                P    dd l } fd}d}|D ]} j                            ddt          |          z  |           |dz  }|                    dd            |j        dd|i|  |            rJ  j                            ddt          |          z  |           |dz  }|                    dd	            |j        d|dd
|  |            rJ |dvrǉ j                            ddt          |          z  |           |dz  }|                    dd	            |j        dd|i|  |            sJ  j                            ddt          |          z  |           |dz  }|                    dd            |j        d|d	d
|  |            sJ d S )Nr   c                 2   j                                         j                                        } j                                         j                                        }t          d | D                       }t          d |D                       }|o| S )Nc              3  J   K   | ]}|j                                          V  d S r   gridlinerO   r3   gs     r   	<genexpr>zHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  3      DD1:11333DDDDDDr   c              3  J   K   | ]}|j                                          V  d S r   r   r   s     r   r   zHTestPlotBase._check_grid_settings.<locals>.is_grid_on.<locals>.<genexpr>  r   r   )r   gcar   get_major_ticksr   all)xticksyticksxoffyoffr   s       r   
is_grid_onz5TestPlotBase._check_grid_settings.<locals>.is_grid_on  s    X\\^^)99;;FX\\^^)99;;FDDVDDDDDDDDVDDDDDD&&r   r      r*   F)gridkindT)r   r   )piehexbinscatterr1   )r   r   subplotr>   rcplot)r   objkindskwsr   r   spndxr   s   `       r   _check_grid_settingsz!TestPlotBase._check_grid_settings  s!    	!   	' 	' 	' 	' 	'  	$ 	$DHQCJJ666QJEFF6F&&&CH&&$&#&&&!z||###HQCJJ666QJEFF6F%%%CH2$U22c222!z||###777  AE

NE:::
vD)))**d*c***!z||##|  AE

NE:::
vE***5d55555!z||##|3	$ 	$r   ru   c                ,    fd|d         D             S )zT
        Auxiliary function for correctly unpacking cycler after MPL >= 1.5
        c                     g | ]
}|         S r1   r1   )r3   r^   fields     r   r5   z/TestPlotBase._unpack_cycler.<locals>.<listcomp>  s    >>>Q%>>>r   zaxes.prop_cycler1   )r   rcParamsr   s     `r   _unpack_cyclerzTestPlotBase._unpack_cycler  s%     ?>>>(+<"=>>>>r   c                J    ddl m}  |            r|j        d         S |j        S )Nr   mpl_ge_3_5_0x)"pandas.plotting._matplotlib.compatr   _shared_axes_shared_x_axesr   r-   r   s      r   
get_x_axiszTestPlotBase.get_x_axis  8    CCCCCC<>> 	(?3''  r   c                J    ddl m}  |            r|j        d         S |j        S )Nr   r   y)r   r   r   _shared_y_axesr   s      r   
get_y_axiszTestPlotBase.get_y_axis  r   r   )NT)T)r*   rS   rT   rU   rV   rW   )NNN)NNNN)r   r   )r   r   )ru   )__name__
__module____qualname____doc__r   r   r   r   r#   r.   r;   rJ   rR   r[   rd   rx   r(   r   r   r   r   r&   r   r   r   r   r   r  r1   r   r   r   r      s          
     ^
 % % ^%
/ / / /.+ + + +,  (2 2 2 2( ;?, , , , ,$2 2 2 FJ@* @* @* @*D" " "( GK.K .K .K .K`1 1 1 1""
 "
 "
 "
H( ( (  & & & &8 IM:) :) :) :)x 46 '$ '$ '$ '$R? ? ? ?! ! !! ! ! ! !r   r   alwaysFc                   ddl m} |rt          }nt          }d}t	          j                    5  t	          j        |           	 |                    d|                                          }|	                                  || |fi |D ]}t          j        |           t          j        d          5 }|                    |           ddd           n# 1 swxY w Y   n# t          $ r}	|	d}	~	ww xY wt          j        |           n# t          j        |           w xY w|cddd           S # 1 swxY w Y   dS )aT  
    Create plot and ensure that plot return object is valid.

    Parameters
    ----------
    f : func
        Plotting function.
    filterwarnings : str
        Warnings filter.
        See https://docs.python.org/3/library/warnings.html#warning-filter
    default_axes : bool, optional
        If False (default):
            - If `ax` not in `kwargs`, then create subplot(211) and plot there
            - Create new subplot(212) and plot there as well
            - Mind special corner case for bootstrap_plot (see `_gen_two_subplots`)
        If True:
            - Simply run plotting function with kwargs provided
            - All required axes instances will be created automatically
            - It is recommended to use it when the plotting function
            creates multiple axes itself. It helps avoid warnings like
            'UserWarning: To output multiple subplots,
            the figure containing the passed axes is being cleared'
    **kwargs
        Keyword arguments passed to the plotting function.

    Returns
    -------
    Plot object returned by the last plotting.
    r   Nr   T)return_filelike)r   r   _gen_default_plot_gen_two_subplotswarningscatch_warningssimplefiltergetgcfclfr   "assert_is_valid_plot_return_objectensure_cleansavefig	Exceptionr   )
ffilterwarningsdefault_axeskwargsr   	gen_plotsretfigpatherrs
             r   _check_plot_worksr    s   < $##### &%		%	
C		 	"	"  n---	**Xswwyy11CGGIII yC22622 ; ;5c::::666 "$D!!!" " " " " " " " " " " " " " "  	 	 	I	 HSMMMMBHSMMMM#                 sl   D3A2C#5CC#C	C#C	C#"D#
C4-C//C44D7D3D""D33D7:D7c              +     K    | di |V  dS )z'
    Create plot in a default way.
    Nr1   r1   r  r  r  s      r   r	  r	  E  s&       !++f++r   c              +     K   d|vr|                     d            | di |V  | t          j        j        u rd|vsJ n|                     d          |d<    | di |V  dS )z9
    Create plot on two subplots forcefully created.
    r-         Nr1   )add_subplotpdplottingbootstrap_plotr   s      r   r
  r
  L  s       6
!++f++BK&&&6!!!!!s++t
!++f++r   )r  F)r  
__future__r   typingr   r   r  numpyro   pandas.util._decoratorsr   pandas.util._test_decoratorsutil_test_decoratorstdpandas.core.dtypes.apir   pandasr%  r   pandas._testing_testingr   r   r
   skip_if_no_mplr   r  r	  r
  r1   r   r   <module>r5     si    # " " " " "             2 2 2 2 2 2 ) ) ) ) ) ) ) ) ) / / / / / /                 %$$$$$$ k! k! k! k! k! k! k! k!\7 7 7 7t      r   