
    I.eƏ                        d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddlZddlZddlZddlZddlmZmZmZmZ ddlmZmZ ddlmZ d	d
lmZ d	dlmZm Z m!Z!m"Z"m#Z#m$Z$ d Z% G d d          Z& G d d          Z'dS )a  
interactive API

How Interactive works
---------------------

`Interactive` is a wrapper around a Python object that lets users create
interactive pipelines by calling existing APIs on an object with dynamic
parameters or widgets.

An `Interactive` instance watches what operations are applied to the object.

To do so, each operation returns a new `Interactive` instance - the creation
of a new instance being taken care of by the `_clone` method - which allows
the next operation to be recorded, and so on and so forth. E.g. `dfi.head()`
first records that the `'head'` attribute is accessed, this is achieved
by overriding `__getattribute__`. A new interactive object is returned,
which will then record that it is being called, and that new object will be
itself called as `Interactive` implements `__call__`. `__call__`  returns
another `Interactive` instance.

Note that under the hood even more `Interactive` instances may be created,
but this is the gist of it.

To be able to watch all the potential operations that may be applied to an
object, `Interactive` implements on top of `__getattribute__` and
`__call__`:

- operators such as `__gt__`, `__add__`, etc.
- the builtin functions `__abs__` and `__round__`
- `__getitem__`
- `__array_ufunc__`

The `_depth` attribute starts at 0 and is incremented by 1 every time
a new `Interactive` instance is created part of a chain.
The root instance in an expression has a `_depth` of 0. An expression can
consist of multiple chains, such as `dfi[dfi.A > 1]`, as the `Interactive`
instance is referenced twice in the expression. As a consequence `_depth`
is not the total count of `Interactive` instance creations of a pipeline,
it is the count of instances created in the outer chain. In the example, that
would be `dfi[]`. `Interactive` instances don't have references about
the instances that created them or that they create, they just know their
current location in a chain thanks to `_depth`. However, as some parameters
need to be passed down the whole pipeline, they do have to propagate. E.g.
in `dfi.interactive(width=200)`, `width=200` will be propagated as `kwargs`.

Recording the operations applied to an object in a pipeline is done
by gradually building a so-called "dim expression", or "dim transform",
which is an expression language provided by HoloViews. dim transform
objects are a way to express transforms on `Dataset`s, a `Dataset` being
another HoloViews object that is a wrapper around common data structures
such as Pandas/Dask/... Dataframes/Series, Xarray Dataset/DataArray, etc.
For instance a Python expression such as `(series + 2).head()` can be
expressed with a dim transform whose repr will be `(dim('*').pd+2).head(2)`,
effectively showing that the dim transform has recorded the different
operations that are meant to be applied to the data.
The `_transform` attribute stores the dim transform.

The `_obj` attribute holds the original data structure that feeds the
pipeline. All the `Interactive` instances created while parsing the
pipeline share the same `_obj` object. And they all wrap it in a `Dataset`
instance, and all apply the current dim transform they are aware of to
the original data structure to compute the intermediate state of the data,
that is stored it in the `_current_` attribute. Doing so is particularly
useful in Notebook sessions, as this allows to inspect the transformed
object at any point of the pipeline, and as such provide correct
auto-completion and docstrings. E.g. executing `dfi.A.max?` in a Notebook
will correctly return the docstring of the Pandas Series `.max()` method,
as the pipeline evaluates `dfi.A` to hold a current object `_current` that
is a Pandas Series, and no longer and DataFrame.

The `_obj` attribute is implemented as a property which gets/sets the value
from a list that contains the shared attribute. This is required for the
"function as input" to be able to update the object from a callback set up
on the root Interactive instance.

Internally interactive holds the current evaluated state on the `_current_`
attribute, when some parameter in the interactive pipeline is changed
the pipeline is marked as `_dirty`. This means that the next time `_current`
is accessed the pipeline will be re-evaluated to get the up-to-date
current value.

The `_method` attribute is a string that temporarily stores the method/attr
accessed on the object, e.g. `_method` is 'head' in `dfi.head()`, until the
Interactive instance created in the pipeline is called at which point `_method`
is reset to None. In cases such as `dfi.head` or `dfi.A`, `_method` is not
(yet) reset to None. At this stage the Interactive instance returned has
its `_current` attribute not updated, e.g. `dfi.A._current` is still the
original dataframe, not the 'A' series. Keeping `_method` is thus useful for
instance to display `dfi.A`, as the evaluation of the object will check
whether `_method` is set or not, and if it's set it will use it to compute
the object returned, e.g. the series `df.A` or the method `df.head`, and
display its repr.
    N)partial)Version)FunctionType
MethodType)ColumnRowVSpacerHSpacer)get_method_ownerfull_groupbyWidget   )HoloViewsConverter)_flattenbokeh3
is_tabular	is_xarrayis_xarray_dataarray_convert_col_names_to_strc                    g }t          | d                   t          | d                                                   z   }t          |          }|D ]}t          |t                    r||vr|                    |           t          |t          j                  r5|j        D ]-}t          |          D ]}||vr|                    |           .dt          j        v r/ddlm} t          ||          r||vr|                    |           t          |t          j                  rGt          |j        t           j        j                  r#|j        |vr|                    |j                   t          |t$                    r{t'          t          j                  t'          d          k     rt+          d          |j        |j        |j        gi d}t          |          D ]}||vr|                    |           |S )	Nargskwargs
ipywidgetsr   r   z1.15.1zRUsing interactive with slices needs to have Holoviews 1.15.1 or greater installed.)r   r   )listvaluesr   
isinstancer   appendhvdimops_find_widgetssysmodulesr   param	Parameterownerpnwidgetsslicer   __version__
ValueErrorstartstopstep)opr)   op_argsop_arg	nested_opwidget	IPyWidgets          2lib/python3.11/site-packages/hvplot/interactive.pyr"   r"   x   s   G2f:bl&9&9&;&;!<!<<GwG + +ff%% 	#&*?*?NN6"""fbf%% 	/#Z / /	+I66 / /FW,,v.../ 3;&&666666&),, 'w1F1Fv&&&vu// 	)v|RZ%677	)L''NN6<(((fe$$ 		+r~&&):)::: =   #),V[!IUWXXI'	22 + +((NN6***N    c                       e Zd ZdZej        ZdZ fdZe	d             Z
dddddddi ddddfd	Zed
             Zej        d             Zed             Zed             Zed             ZdKdZd Zd Zed             Z	 	 dLdZg g fdZ fdZd Z fdZed             Zd Zd ZdddZd Z dMdZ!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d( Z+d) Z,d* Z-d+ Z.d, Z/d- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z>d< Z?d= Z@d> ZAd? ZBd@ ZCdA ZDdB ZEdC ZFdD ZGdE ZHdF ZIdG ZJdH ZKdI ZLdJ ZM xZNS )NInteractivea  
    The `.interactive` API enhances the API of data analysis libraries
    like Pandas, Dask, and Xarray, by allowing to replace in a pipeline
    static values by dynamic widgets. When displayed, an interactive
    pipeline will incorporate the dynamic widgets that control it, as long
    as its normal output that will automatically be updated as soon as a
    widget value is changed.

    `Interactive` can be instantiated with an object. However the recommended
    approach is to instantiate it via the `.interactive` accessor that is
    available on a data structure when it has been patched, e.g. after
    executing `import hvplot.pandas`. The accessor can also be called which
    allows to pass down kwargs.

    A pipeline can then be created from this object, the pipeline will render
    with its widgets and its interactive output.

    Reference: https://hvplot.holoviz.org/user_guide/Interactive.html

    Parameters
    ----------
    obj: DataFrame, Series, DataArray, DataSet
        A supported data structure object
    loc : str, optional
        Widget(s) location, one of 'bottom_left', 'bottom_right', 'right'
        'top-right', 'top-left' and 'left'. By default 'top_left'
    center : bool, optional
        Whether to center to pipeline output, by default False
    max_rows : int, optional
        Maximum number of rows displayed, only used when the output is a
        dataframe, by default 100
    kwargs: optional
        Optional kwargs that are passed down to customize the displayed
        object. E.g. if the output is a DataFrame `width=200` will set
        the size of the DataFrame Pane that renders it.

    Examples
    --------
    Instantiate it from an object:
    >>> dfi = Interactive(df)

    Or with the `.interactive` accessor when the object is patched:
    >>> import hvplot.pandas
    >>> dfi = df.interactive
    >>> dfi = df.interactive(width=200)

    Create interactive pipelines from the `Interactive` object:
    >>> widget = panel.widgets.IntSlider(value=1, start=1, end=5)
    >>> dfi.head(widget)
    Nc                    d|v r|                     d          }nJt          |t          t          f          r,t	          j        |d          }|                    |          }nd }| }|                                 D ]}|                    |          r|}t                      
                    |          }|                    d|g          |_        ||_        |S )NfnT)lazy_shared_obj)popr   r   r   r(   paneleval__subclasses__appliessuper__new__getr=   _fn)clsobjr   r;   clsssubclsinst	__class__s          r6   rD   zInteractive.__new__   s     6>>D!!BBlJ788 	#D)))B''#,,CCB((** 	 	F~~c"" wwt$$!::mcU;;r7   c                     dS )z
        Subclasses must implement applies and return a boolean to indicate
        whether the subclass should apply or not to the obj.
        T )rG   rH   s     r6   rB   zInteractive.applies   s	     tr7   Fr   top_leftd   c                    d| _         || _        |d}t          j        j        j        }t          |          r>t          j        j        j        }t          |          r|j	        }|t          d          n%t          |          rt          j        j        j        } ||          | _        n|| _        || _        || _        || _        || _        || _        |	| _        |
| _        || _        t          j        t/          | j                            }||| _        n"| j                            |dd          | _        d| _         d| _        t9          |           | _        |                     |           d S )NF*zbCannot use interactive API on DataArray without name.Assign a name to the DataArray and try again.T
keep_indexcompute)_init_methodr   util	transformr    r   xr_dimr   namer,   r   df_dim
_transform_plot_depth_loc_center_dmap_inherit_kwargs	_max_rows_kwargsDatasetr   _obj	_current_apply_dirty_hvplothvplot_setup_invalidations)selfrH   rY   r;   plotdepthloccenterdmapinherit_kwargsmax_rowsmethodr=   _currentr   r    dss                    r6   __init__zInteractive.__init__   sk    
C)-I~~ 
5G-4	&s++ #(C;$H   
 C 5G-4	'innDOO'DO
	
  .!Z1$)<<==%DNN!_222$PU2VVDN
dmm!!%(((((r7   c                     | j         d         S Nr   r=   rn   s    r6   rg   zInteractive._obj   s    ""r7   c                 <    | j         
|g| _         d S || j         d<   d S r{   r|   )rn   rH   s     r6   rg   zInteractive._obj$  s.    # #uD"%DQr7   c                 F    | j         r|                                  | j        S N)rj   r@   rh   r}   s    r6   rw   zInteractive._current+  s!    ; 	IIKKK~r7   c                    | j         g }nt          | j         t          j        j                  rut          | j         j        di           }t          |                    dg                     t          |                    di           	                                          z   }nBt          | j         j                  }|j                            | j         j        j                  }|S )N_dinfodependencieskw)rF   r   r(   r%   ParamFunctiongetattrobjectr   rE   r   r   method_dependencies__name__)rn   depsdinfoparameterizeds       r6   
_fn_paramszInteractive._fn_params1  s    8DD"("899 	UDHOXr::E		."5566eiib>Q>Q>X>X>Z>Z9[9[[DD -TX_==M &::48?;STTDr7   c                     | j         }| j        j                                        D ]%\  }}|dk    s||v r|                    |           &|S )Nax)r   r]   paramsitemsr   )rn   pskps       r6   _paramszInteractive._params>  sW    _O*0022 	 	DAqDyyAGGIIaLLLL	r7   c                 d   | j         W|dk    rQt          | j        d           D ]:\  }}|d         j        j                            | j        d |D                        ;t          | j        d           D ]:\  }}|d         j        j                            | j        d |D                        ;dS )a  
        Since the parameters of the pipeline can change at any time
        we have to invalidate the internal state of the pipeline.
        To handle both invalidations of the inputs of the pipeline
        and the pipeline itself we set up watchers on both.

        1. The first invalidation we have to set up is to re-evaluate
           the function that feeds the pipeline. Only the root node of
           a pipeline has to perform this invalidation because all
           leaf nodes inherit the same shared_obj. This avoids
           evaluating the same function for every branch of the pipeline.
        2. The second invalidation is for the pipeline itself, i.e.
           if any parameter changes we have to notify the pipeline that
           it has to re-evaluate the pipeline. This is done by marking
           the pipeline as `_dirty`. The next time the `_current` value
           is requested we then run and `.eval()` pass that re-executes
           the pipeline.
        Nr   c                 *    t          | j                  S r   idr'   xs    r6   <lambda>z2Interactive._setup_invalidations.<locals>.<lambda>[  s    R[[ r7   c                     g | ]	}|j         
S rN   r[   .0r   s     r6   
<listcomp>z4Interactive._setup_invalidations.<locals>.<listcomp>\  s    >V>V>V!qv>V>V>Vr7   c                 *    t          | j                  S r   r   r   s    r6   r   z2Interactive._setup_invalidations.<locals>.<lambda>]  s    bkk r7   c                     g | ]	}|j         
S rN   r   r   s     r6   r   z4Interactive._setup_invalidations.<locals>.<listcomp>^  s    BZBZBZa16BZBZBZr7   )	rF   r   r   r'   r%   watch_update_objr   _invalidate_current)rn   rp   _r   s       r6   rm   z Interactive._setup_invalidationsG  s    & 8EQJJ)$/;P;PQQ X X	6q	%++D,<>V>Vv>V>V>VWWWW%dl4I4IJJ 	\ 	\IAv1IO!''(@BZBZSYBZBZBZ[[[[	\ 	\r7   c                     d| _         d S )NT)rj   )rn   eventss     r6   r   zInteractive._invalidate_current`  s    r7   c                 X    | j                             | j         j                  | _        d S r   )rF   r@   r   rg   )rn   r   s     r6   r   zInteractive._update_objc  s    HMM$(/22			r7   c                 d      fd j         }|rt          j        | fd            }nfd}|S )Nc                                                       } t          | t          j                  r#t	          j        j        | fdj        ij        S | S )Nru   )r@   r   pd	DataFramer(   panerd   re   )rH   rn   s    r6   evaluate_innerz-Interactive._callback.<locals>.evaluate_innerh  sN    ))++C#r|,, Ww(VVt~VVVVJr7   c                                   S r   rN   )r   r   r   s     r6   evaluatez'Interactive._callback.<locals>.evaluateo  s    %~'''r7   c                                    S r   rN   )r   s   r6   r   z'Interactive._callback.<locals>.evaluates  s    %~'''r7   )r   r(   depends)rn   r   r   r   s   `  @r6   	_callbackzInteractive._callbackf  s|    	 	 	 	 	
  	(Z ( ( ( ( ! ( (( ( ( ( (r7   c                    | j         p|}|p| j        }|| j        n|}|| j        n|}|| j        n|}|| j        n|}| j        dz   }	|r&t          | j        f| j	        | j
        | j        d|}n"t          | j
        fi t          | j        fi |} t          |           | j        f| j        |||	|||| j        |d	|S )Nr   )rw   rt   rv   )	r;   rY   ro   rp   rq   rr   rs   r=   ru   )r^   r]   r`   ra   rb   rd   r_   dictre   rw   rc   rW   typerg   rF   r=   )
rn   rY   ro   rq   rr   rs   copyru   r   rp   s
             r6   _clonezInteractive._clonew  s   z!T0	;diiC!'V!\tzzt%-%54>>8a 	P$,  DtOclplx  D  D  }C  D  DFF$.OO$t|2N2Nv2N2NOOFtDzz$) 6IDX] dHX"*6 6.46 6 	6r7   c                 N    |                                                                  S r   )layout_repr_mimebundle_)rn   includeexcludes      r6   r   zInteractive._repr_mimebundle_  s    {{}}..000r7   c           
          | j         }| j        rt          || j                  }d t          |          D             }t	          |          r't          |d          r|t          |j                  z  }	 t          t          t                      
                                          |z            S # t          $ rQ t          t          t          t          |                               t          | j                  z  |z            cY S w xY w)Nc                 <    h | ]}|                     d           |S r   
startswith)r   attrs     r6   	<setcomp>z&Interactive.__dir__.<locals>.<setcomp>  s)    LLL4ts7K7KL$LLLr7   columns)rw   rW   r   dirr   hasattrsetr   sortedrC   __dir__	Exceptionr   __dict__)rn   currentextrasrL   s      r6   r   zInteractive.__dir__  s    -< 	5gt|44GLL3w<<LLLg 	+77I#>#> 	+c'/***F	N#eggoo//0069::: 	N 	N 	N#c$t**oo..T]1C1CCfLMMMMM	Ns   5<B2 2ADDc                 L   | j         s|                     d          S  t          | j                  | j        | j         d          }| j        |_        i }| j         dk    r|                                 |d<   	 |                     ||          }d | _         n# d | _         w xY w|S )NTr   accessorro   r   )rt   )rW   r   r   r]   rw   _ns
_get_ax_fn)rn   rY   rt   news       r6   _resolve_accessorzInteractive._resolve_accessor  s    | 	*;;D;))) *D))$/4<RVWWW		<6!!#'??#4#4N4 	 ++i+GGC  DLL4DL
s   9B 	B!c                 H   t                                          d          }|                    d          s!t                                          |          S |d         }|d         }|rt          ||          }d t	          |          D             }||v rk|t                                                      vrI|                                 }||_        	 t          ||          j        |_        n# t          $ r Y nw xY w|S t                                          |          S )Nr   rV   rh   rW   c                 <    g | ]}|                     d           |S r   r   )r   ds     r6   r   z0Interactive.__getattribute__.<locals>.<listcomp>  s)    CCCc1B1BC!CCCr7   )
rC   __getattribute__rE   r   r   r   r   rW   __doc__r   )rn   r[   	self_dictr   rv   r   r   rL   s          r6   r   zInteractive.__getattribute__  s    GG,,Z88	}}W%% 	277++D111K(9% 	/gv..G DCS\\CCC6>>d%''//*;*;;;((**C CK%gt44<   Jww''---s   C1 1
C>=C>c                  >    t          j                    d             } | S )Nc                      ddl m}  ddlm}  |            xt          _        } | |           |                                S Nr   )FigureCanvas)Figurematplotlib.backends.backend_aggr   matplotlib.pyplotr   r9   _figsubplotsr   r   figs      r6   get_axz&Interactive._get_ax_fn.<locals>.get_ax  W    DDDDDD000000%+VXX-KsL<<>>!r7   )r(   r   )r   s    r6   r   zInteractive._get_ax_fn  s(    		" 	" 
	" r7   c                    | j         | j        dk    r | j        |i |S t          | j         dk    r|                                 |d<   |                     d          }	  t          |j                  |j        |j         d          }t          |j        fi |}|                     ||i ||j         dk              }d|_         n# d|_         w xY w|S )	a  
        The `.interactive` API enhances the API of data analysis libraries
        like Pandas, Dask, and Xarray, by allowing to replace in a pipeline
        static values by dynamic widgets. When displayed, an interactive
        pipeline will incorporate the dynamic widgets that control it, as long
        as its normal output that will automatically be updated as soon as a
        widget value is changed.

        Reference: https://hvplot.holoviz.org/user_guide/Interactive.html

        Parameters
        ----------
        loc : str, optional
            Widget(s) location, one of 'bottom_left', 'bottom_right', 'right'
            'top-right', 'top-left' and 'left'. By default 'top_left'
        center : bool, optional
            Whether to center to pipeline output, by default False
        max_rows : int, optional
            Maximum number of rows displayed, only used when the output is a
            dataframe, by default 100
        kwargs: optional
            Optional kwargs that are passed down to customize the displayed
            object. E.g. if the output is a DataFrame `width=200` will set
            the size of the DataFrame Pane that renders it.

        Returns
        -------
        Interactive
            The next `Interactive` object of the pipeline.

        Examples
        --------
        >>> widget = panel.wid7ugets.IntSlider(value=1, start=1, end=5)
        >>> dfi = df.interactive(width=200)
        >>> dfi.head(widget)
        Nr   ro   r   Tr   r   ro   )	rW   r_   r   AttributeErrorr   r   r]   r   rc   )rn   r   r   r   rv   clones         r6   __call__zInteractive.__call__  s    L <{a
 #t{D3F333  \V##  ??,,F4Lkktk$$	)T#.))#.#+PTUUUF#-8888FJJvvt6v66S[F=RJSSE CKK$CKs    A"C
 
	Cc                     |                                  }|j        } |d         |g|dd          R i |}|                    |          S )Nr      )r   r]   r   )rn   r   r   r   rY   s        r6   __array_ufunc__zInteractive.__array_ufunc__  sW    $$&&N	DGI;QRR;;;F;;	zz)$$$r7   reversec                    |                                  }|j        } t          |          ||g|R d|i}|                    |          S )Nr   )r   r]   r   r   )rn   operatorr   r   r   r   rY   s          r6   _apply_operatorzInteractive._apply_operator  sS    $$&&N	#DOOIxP$PPPPP	zz)$$$r7   c                 6    |                      t                    S r   )r   absr}   s    r6   __abs__zInteractive.__abs__  s    ##C(((r7   c                 6    |dn|f} | j         t          g|R  S )NrN   )r   round)rn   ndigitsr   s      r6   	__round__zInteractive.__round__"  s,    _rr7*#t#E1D1111r7   c                 @    |                      t          j                  S r   )r   r   negr}   s    r6   __neg__zInteractive.__neg__'      ##HL111r7   c                 @    |                      t          j                  S r   )r   r   not_r}   s    r6   __not__zInteractive.__not__)  s    ##HM222r7   c                 @    |                      t          j                  S r   )r   r   invr}   s    r6   
__invert__zInteractive.__invert__+  r  r7   c                 @    |                      t          j                  S r   )r   r   posr}   s    r6   __pos__zInteractive.__pos__-  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   addrn   others     r6   __add__zInteractive.__add__1  6    $.uk$B$BM  ##HL%888r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   and_r  s     r6   __and__zInteractive.__and__4  s6    $.uk$B$BM  ##HM5999r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   eqr  s     r6   __eq__zInteractive.__eq__7  6    $.uk$B$BM  ##HK777r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   floordivr  s     r6   __floordiv__zInteractive.__floordiv__:  s7    $.uk$B$BM  ##H$5u===r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   ger  s     r6   __ge__zInteractive.__ge__=  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   gtr  s     r6   __gt__zInteractive.__gt__@  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   ler  s     r6   __le__zInteractive.__le__C  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   ltr  s     r6   __lt__zInteractive.__lt__F  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   lshiftr  s     r6   
__lshift__zInteractive.__lshift__I  6    $.uk$B$BM  ##HOU;;;r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   modr  s     r6   __mod__zInteractive.__mod__L  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   mulr  s     r6   __mul__zInteractive.__mul__O  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   ner  s     r6   __ne__zInteractive.__ne__R  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   or_r  s     r6   __or__zInteractive.__or__U  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   rshiftr  s     r6   
__rshift__zInteractive.__rshift__X  r0  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   powr  s     r6   __pow__zInteractive.__pow__[  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   subr  s     r6   __sub__zInteractive.__sub__^  r  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   r   r9   r]   r   r   truedivr  s     r6   __truediv__zInteractive.__truediv__a  7    $.uk$B$BM  ##H$4e<<<r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S NTr   r  r  s     r6   __radd__zInteractive.__radd__f  ;    $.uk$B$BM  ##HL%#FFFr7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  r  r  s     r6   __rand__zInteractive.__rand__i  s;    $.uk$B$BM  ##HM5$#GGGr7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  )r   r9   r]   r   r   divr  s     r6   __rdiv__zInteractive.__rdiv__l  rS  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  r  r  s     r6   __rfloordiv__zInteractive.__rfloordiv__o  s<    $.uk$B$BM  ##H$5ud#KKKr7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   rlshiftr  s     r6   __rlshift__zInteractive.__rlshift__r  rO  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  r2  r  s     r6   __rmod__zInteractive.__rmod__u  rS  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  r6  r  s     r6   __rmul__zInteractive.__rmul__x  rS  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  r=  r  s     r6   __ror__zInteractive.__ror__{  rS  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  rD  r  s     r6   __rpow__zInteractive.__rpow__~  rS  r7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   rrshiftr  s     r6   __rrshift__zInteractive.__rrshift__  rO  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  rH  r  s     r6   __rsub__zInteractive.__rsub__  rS  r7   c                     t          |t                    r|j        n|}|                     t          j        |d          S rQ  rL  r  s     r6   __rtruediv__zInteractive.__rtruediv__  s<    $.uk$B$BM  ##H$4eT#JJJr7   c                 ~    t          |t                    r|j        n|}|                     t          j        |          S r   )r   r9   r]   r   r   getitemr  s     r6   __getitem__zInteractive.__getitem__  rO  r7   c                     t          j                    d             }||d<   |                                 }|j        } t	          |          |dd          }|                     ||i |d          S )Nc                      ddl m}  ddlm}  |            xt          _        } | |           |                                S r   r   r   s      r6   r   z!Interactive._plot.<locals>.get_ax  r   r7   r   ro   Tr   r   )r(   r   r   r]   r   r   )rn   r   r   r   r   rY   s         r6   r^   zInteractive._plot  s    		" 	" 
	" t$$&&N	#DOOIvEEE	zz))T4V444z@@@r7   c                 4    t          j        | j                  S )zk
        Wraps the output in a DynamicMap. Only valid if the output
        is a HoloViews object.
        r   
DynamicMapr   r}   s    r6   rs   zInteractive.dmap  s    
 }T^,,,r7   c                    | j         r| j        }t          j        t	          |                    }| j        }|j        j        dk    r)t          |          r|	                    |j
                  }|                    |dd          }|| _        d| _         n| j        }| j        rt          || j        |          }| j        rt           j        }|S )z
        Returns the current state of the interactive expression. The
        returned object is no longer interactive.
        xarrayTFrS   )rj   rg   r   rf   r   r]   	interfacedatatyper   r   r[   ri   rh   rW   r   r^   r9   r   )rn   rH   rx   rY   s       r6   r@   zInteractive.eval  s    
 ; 
	!)C5c::;;BI|$005H5M5M0%OOCH55	//"u/EEC DNDKK.C< 	2#t|S11C: 	#"C
r7   c                 D    t           r | j        di |S  | j        di |S )z
        Returns a layout of the widgets and output arranged according
        to the center and widget location specified in the
        interactive call.
        rN   )r   _layout_bk3_layout_bk2rn   r   s     r6   r   zInteractive.layout  s>      	.#4#--f---t))&)))r7   c           
         |                                  }|                                 }| j        }|dv r*t          t	                      |t	                                }n|dv r*t          t                      |t                                }n|dv rt          |t                                }nb|dv rt          t                      |          }nA|dv rt          |t	                                }n |dv rt          t	                      |          }| j        }|s&|rt                      |t                      g}n|g}n|r:|                    d          r |t                      |t                      g}n|                    d          r t                      |t                      |g}nQ|                    d	          rSt                      t          |t          t                      |t                                          t                      g}n|                    d
          rRt                      t          t          t                      |t                                |          t                      g}n|                    d          r||g}ng|                    d          r||g}nM|                    d	          rt          ||          g}n&|                    d
          rt          ||          g}t          |i |S )N)leftright)topbottom)rO   bottom_left)	top_rightbottom_right)left_top	right_top)left_bottomright_bottomr~  r  r  r  )	r)   outputr`   r   r	   r   r
   ra   r   )rn   r   
widget_boxr?   rq   r)   rr   
componentss           r6   r{  zInteractive._layout_bk2  s   \\^^
i###WYY
GII>>GG%%%'))Z;;GG///*gii00GG111'))Z00GG---Z33GG333WYY
33G 	6 %%ii		:

#W

 	6~~f%% g%wyy%C

(( g%ii		7C

&& g%iiWYYwyy9Y9Y)Z)Z\c\e\ef

)) g%iiGIIugii0P0PRY)Z)Z\c\e\ef
~~f%% 6%u-

(( 6#W-

&& 6$We445

)) 6$UG445
J)&)))r7   c                    |                                  }|                                 }| j        }| j        }t          ddft          ddft
          ddft
          ddft
          ddft
          ddft
          d	dft
          d
dft          ddft          d	dft          ddft          d
dfd}||         \  }}}	||_        t          |          s/|rt                      |t                      g}
n|g}
t	          |
i |S |	r||fn||f}|	                    d          }|s#|t          u rt          |          }
n ||d|ig}
n|t
          u r$t                       ||d|it                      g}
nR|                    d          r|t                      |t                      g}
nt                      |t                      |g}
t	          |
i |S )N)r-   rr   T)endrr   F)rr   r-   )rr   r  r-   )r  r-   )r-   r  r  )r~  r  r  r  rO   r  r  r  r  r  r  r  sizing_moder~  )r)   r  r`   ra   r   r   alignlenr
   rE   r   r   )rn   r   r  r?   rq   rr   
alignmentsr   r  widget_firstr  r   r  s                r6   rz  zInteractive._layout_bk3  s   \\^^
i-t4,e4/60%8$/ "2D9"$4e<#UE2gt,!148/7 %/
 

 '1o#| 
: 	. %%ii		:

#W

-f---'3LU##%9Ljj// 
	C}}!%[[

$feEEEF

v!))VVU%L%L%LgiiXJJ^^F## 	C$gii		BJJ!))UGIIzBJJ)&)))r7   c                 4    t          j        | j                  S )z
        Returns a HoloViews object to render the output of this
        pipeline. Only works if the output of this pipeline is a
        HoloViews object, e.g. from an .hvplot call.
        rs  r}   s    r6   	holoviewszInteractive.holoviews"  s     }T^,,,r7   c                 \    | j         r|                                 n | j        di | j        S )z
        Returns the output of the interactive pipeline, which is
        either a HoloViews DynamicMap or a Panel object.

        Returns
        -------
        DynamicMap or Panel object wrapping the interactive output.
        rN   )rb   r  r?   re   r}   s    r6   r  zInteractive.output*  s4     $(:Mt~~:4:3M3M3M3MMr7   c                 0    t          j        | j        fi |S )z8
        Wraps the output in a Panel component.
        )r(   r?   r   r|  s     r6   r?   zInteractive.panel5  s     x11&111r7   c                 8   g }| j         D ]I}t          |j        t          j        j                  r#|j        |vr|                    |j                   J| j        j        D ]-}t          |          D ]}||vr|                    |           .t          j
        | S )z
        Returns a Column of widgets which control the interactive output.

        Returns
        -------
        A Column of widgets
        )r   r   r'   r(   r)   r   r   r]   r!   r"   r   )rn   r)   r   r0   ws        r6   r)   zInteractive.widgets;  s      	( 	(A17BJ$566 (w&&qw'''/% 	& 	&B"2&& & &G##NN1%%%& y'""r7   )r   )NNNNNFNr   )Or   
__module____qualname__r   abcABCMeta__metaclass__r   rD   classmethodrB   ry   propertyrg   setterrw   r   r   rm   r   r   r   r   r   r   r   r   staticmethodr   r   r   r   r   r   r  r  r
  r  r  r  r  r   r#  r&  r)  r,  r/  r4  r8  r;  r?  rB  rF  rJ  rN  rR  rU  rX  rZ  r]  r_  ra  rc  re  rh  rj  rl  ro  r^   rs   r@   r   r{  rz  r  r  r?   r)   __classcell__)rL   s   @r6   r9   r9      s.       1 1h KM D    &   [ '+t%qE"dt+) +) +) +)Z # # X# 
[& & [&   X
 
 
 X
   X\ \ \ \2  3 3 3   X  BF/36 6 6 6" )+B 1 1 1 1
N 
N 
N 
N 
N  (. . . . .0   \< < <D% % % 8= % % % % %) ) )2 2 2 2
2 2 23 3 32 2 22 2 29 9 9: : :8 8 8> > >8 8 88 8 88 8 88 8 8< < <9 9 99 9 98 8 89 9 9< < <9 9 99 9 9= = =
G G GH H HG G GL L L= = =G G GG G GG G GG G G= = =G G GK K K= = =A A A&- - -  2* * *)* )* )*V)* )* )*V- - -	N 	N 	N2 2 2# # # # # # #r7   r9   c                   R    e Zd Z eej                  ZdgZd ZdddZ	d Z
d ZdS )rk   _interactivec                     || _         d S r   )r  )rn   r  s     r6   ry   z_hvplot.__init__T  s    (r7   N_kindc                .   |rd|v rt          | d          |r||d<   | j                                        }|j        } t	          |          |dd          }d|vpt          |d         t                    }|                     ||i ||          S )Nkindz,() got an unexpected keyword argument 'kind'rl   Tr   )rs   )	TypeErrorr  r   r]   r   r   strr   )rn   r  r   r   r   rY   rs   s          r6   r   z_hvplot.__call__W  s      	TVv%%uRRRSSS 	#"F6N1133N	#DOOIx$GGG	V#Fz&.#'F'Fzz))T4V444z@@@r7   c                 \    || j         v rt          | |          S t          d| d          )Nr  z"'hvplot' object has no attribute '')_kindsr   r   )rn   r   s     r6   __getattr__z_hvplot.__getattr__f  s<    4;4t,,,, !Md!M!M!MNNNr7   c                 .    | j         j        j        j        S r   )r  rg   rl   __all__r}   s    r6   r   z_hvplot.__dir__l  s     %,44r7   )r   r  r  tupler   _kind_mappingr  	__slots__ry   r   r  r   rN   r7   r6   rk   rk   O  s        U%344F I) ) ) %) A A A A AO O O5 5 5 5 5r7   rk   )(r   r  r   r#   	functoolsr   packaging.versionr   typesr   r   r  r   pandasr   r?   r(   r%   panel.layoutr   r   r	   r
   
panel.utilr   r   panel.widgets.baser   	converterr   rX   r   r   r   r   r   r   r"   r9   rk   rN   r7   r6   <module>r     s  ] ]~ 


  



       % % % % % % * * * * * * * *              6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 % % % % % % ) ) ) ) ) )               " " "Jo
# o
# o
# o
# o
# o
# o
# o
#d5 5 5 5 5 5 5 5 5 5r7   