
    Mh                      S r SSKJr  SSKJrJr  SSKrSSKJr  SSK	J
r
JrJrJr  SSKrSSKrSSKrSSKJrJrJrJr  SSKJr  SS	KJrJrJrJrJ r J!r!J"r"J#r#  SS
K$J%r%  SSK&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=  SSK>J?r?J@r@  SSKAJBrBJCrC  SSKDJErEJFrF  SSKGJHrHJIrIJJrJJKrKJLrL  SSKMJNs  JOrP  SSKQJRrRJSrSJTrT  SSKUJVrV  SSKWJNs  JXrY  SSKZJ[r[J\r\  SSK]J^r^  SSK_J`r`  SSKaJbrbJcrc  \
(       a  SSKGJdrd  SSKeJfrf  SSKQJgrg  SSKhJiri  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \GR                   \GR                  \GR                  \GR                  \GR                  \GR
                  0r\GR                  \R                  La  \R                  \\GR                  '   \GR                  \T\J\C4r\(" S5      \'" \^SS9           S;                           S<S  jj5       5       r          S=                         S>S! jjr    S?S" jr        S@                 SAS# jjr            SB                       SCS$ jjr " S% S&5      r  SD         SES' jjr  SD         SFS( jjr            SGS) jr " S* S+\5      rSHS, jr " S- S.\5      r        SIS/ jrSJS0 jr      SKS1 jr SL         SMS2 jjr SN       SOS3 jjr      SPS4 jr        SQS5 jr          SRS6 jrSSS7 jrSSS8 jrSTS9 jr        SUS: jrg)Vz
SQL-style merge routines
    )annotations)HashableSequenceN)partial)TYPE_CHECKINGLiteralcastfinal)	Timedelta	hashtablejoinlib)is_range_indexer)AnyArrayLike	ArrayLike
IndexLabelJoinHowMergeHowShapeSuffixesnpt)
MergeError)AppenderSubstitutioncache_readonly)find_stack_level)ExtensionDtype)find_common_type)ensure_int64ensure_objectis_boolis_bool_dtypeis_float_dtype
is_integeris_integer_dtypeis_list_like	is_numberis_numeric_dtypeis_object_dtypeis_string_dtypeneeds_i8_conversion)CategoricalDtypeDatetimeTZDtype)ABCDataFrame	ABCSeries)isnana_value_for_dtype)
ArrowDtypeCategoricalIndex
MultiIndexSeries)ArrowExtensionArrayBaseMaskedArrayExtensionArray)StringDtype)ensure_wrapped_if_datetimelikeextract_array)
_merge_doc)default_index)get_group_indexis_int64_overflow_possible)	DataFrame)groupby)DatetimeArray)
FrozenListz!
left : DataFrame or named Series)indentsc                    [        U 5      n[        U5      nUS:X  a  [        UUUUUUUUU	UUU
S9$ [        UUUUUUUUUU	UUS9nUR                  U
S9$ )Ncross)
onleft_onright_on
left_indexright_indexsortsuffixes	indicatorvalidatecopy)
howrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   )_validate_operand_cross_merge_MergeOperation
get_result)leftrightrR   rH   rI   rJ   rK   rL   rM   rN   rQ   rO   rP   left_dfright_dfops                   K/var/www/html/env/lib/python3.13/site-packages/pandas/core/reshape/merge.pymerger^      s    "  %G 'H
g~!#
 	
 !#
 }}$}''    c                    U(       d  U(       d	  Uc  Uc  Ub  [        S5      eS[        R                  " 5        3nU R                  " S0 US0D6n UR                  " S0 US0D6nU/=p4[	        U USUUUUUUUU
UU	S9nX	 U$ )z$
See merge.__doc__ with how='cross'
zMCan not pass on, right_on, left_on or set right_index=True or left_index=True_cross_   inner)rR   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ    )r   uuiduuid4assignr^   )rX   rY   rH   rI   rJ   rK   rL   rM   rN   rQ   rO   rP   	cross_colress                 r]   rU   rU      s    & 	>
 	

 $**,(I;;()Q(DLL*Iq>*E#$G
C 	Jr_   c           
     >  ^ / n[        U [        [        45      (       d  U /n UR                  U SS9nSn[	        U4S jU  5       5      (       a  TR                  U SS9nUR
                  R                  UR                  UR                  S9 HG  u  pxUc  Tn	O TR                  UR                  U   5      n	U" X5      nX}U '   UR'                  U5        MI     SSKJn  U" US	S
9nUR                  US   R                  SS9nX4$ ! [         a    UR                  R                  5       n
U
TR                   Vs/ s H  o[        U
5      ;  d  M  UPM     Os  snf sn-   nUR                  US9n[!        [#        U5      5      Ul        UR'                  U5         GM  f = f)z
groupby & merge; we are always performing a left-by type operation

Parameters
----------
by: field to group
left: DataFrame
right: DataFrame
merge_pieces: function for merging
FrM   Nc              3  @   >#    U  H  oTR                   ;   v   M     g 7fNcolumns).0itemrY   s     r]   	<genexpr>%_groupby_and_merge.<locals>.<genexpr>  s     
0RT5== Rs   )axisrn   r   concatT)ignore_index)ro   rQ   )
isinstancelisttuplerB   all_grouperget_iterator_selected_objrt   takeindicesKeyErrorro   tolistsetreindexrangelenindexappendpandas.core.reshape.concatrv   )byrX   rY   merge_piecespieceslbyrbykeylhsrhslcolsrcolsmergedrv   results     `             r]   _groupby_and_merger      s}    Fb4-((T
,,r,
&CCGC 
0R
000mmBUm+LL--c.?.?chh-O;C	jjS!12 c' r
f+ P2 2F.F^^F1I$5$5E^BF;/  **,5==P=aSZ<O=PPT2$S[1f%s%   D3F7E
E
AFFc
                $  ^^^^^^	^ SUU	UUUU4S jjmUb  Ub  [        S5      eUbn  [        U[        5      (       a  U/n[        U5      R	                  U R
                  5      n
[        U
5      S:w  a  [        U
 S35      e[        XPUU4S j5      u  pU$ Ubn  [        U[        5      (       a  U/n[        U5      R	                  UR
                  5      n
[        U
5      S:w  a  [        U
 S35      e[        XaU U4S j5      u  pU$ T" X5      nU$ )	a  
Perform a merge for ordered data with optional filling/interpolation.

Designed for ordered data like time series data. Optionally
perform group-wise merge (see examples).

Parameters
----------
left : DataFrame or named Series
right : DataFrame or named Series
on : label or list
    Field names to join on. Must be found in both DataFrames.
left_on : label or list, or array-like
    Field names to join on in left DataFrame. Can be a vector or list of
    vectors of the length of the DataFrame to use a particular vector as
    the join key instead of columns.
right_on : label or list, or array-like
    Field names to join on in right DataFrame or vector/list of vectors per
    left_on docs.
left_by : column name or list of column names
    Group left DataFrame by group columns and merge piece by piece with
    right DataFrame. Must be None if either left or right are a Series.
right_by : column name or list of column names
    Group right DataFrame by group columns and merge piece by piece with
    left DataFrame. Must be None if either left or right are a Series.
fill_method : {'ffill', None}, default None
    Interpolation method for data.
suffixes : list-like, default is ("_x", "_y")
    A length-2 sequence where each element is optionally a string
    indicating the suffix to add to overlapping column names in
    `left` and `right` respectively. Pass a value of `None` instead
    of a string to indicate that the column name from `left` or
    `right` should be left as-is, with no suffix. At least one of the
    values must not be None.

how : {'left', 'right', 'outer', 'inner'}, default 'outer'
    * left: use only keys from left frame (SQL: left outer join)
    * right: use only keys from right frame (SQL: right outer join)
    * outer: use union of keys from both frames (SQL: full outer join)
    * inner: use intersection of keys from both frames (SQL: inner join).

Returns
-------
DataFrame
    The merged DataFrame output type will be the same as
    'left', if it is a subclass of DataFrame.

See Also
--------
merge : Merge with a database-style join.
merge_asof : Merge on nearest keys.

Examples
--------
>>> from pandas import merge_ordered
>>> df1 = pd.DataFrame(
...     {
...         "key": ["a", "c", "e", "a", "c", "e"],
...         "lvalue": [1, 2, 3, 1, 2, 3],
...         "group": ["a", "a", "a", "b", "b", "b"]
...     }
... )
>>> df1
  key  lvalue group
0   a       1     a
1   c       2     a
2   e       3     a
3   a       1     b
4   c       2     b
5   e       3     b

>>> df2 = pd.DataFrame({"key": ["b", "c", "d"], "rvalue": [1, 2, 3]})
>>> df2
  key  rvalue
0   b       1
1   c       2
2   d       3

>>> merge_ordered(df1, df2, fill_method="ffill", left_by="group")
  key  lvalue group  rvalue
0   a       1     a     NaN
1   b       1     a     1.0
2   c       2     a     2.0
3   d       2     a     3.0
4   e       3     a     3.0
5   a       1     b     NaN
6   b       1     b     1.0
7   c       2     b     2.0
8   d       2     b     3.0
9   e       3     b     3.0
c                D   > [        U UTTTTTTS9nUR                  5       $ )N)rH   rI   rJ   rN   fill_methodrR   )_OrderedMergerW   )	xyr\   r   rR   rI   rH   rJ   rN   s	      r]   _mergermerge_ordered.<locals>._merger  s3    #	
 }}r_   z*Can only group either left or right framesr   z not found in left columnsc                   > T" X5      $ rm   rd   r   r   r   s     r]   <lambda>merge_ordered.<locals>.<lambda>  s
    'RS-r_   z not found in right columnsc                   > T" X5      $ rm   rd   r   s     r]   r   r     s	    r_   )returnrA   )	
ValueErrorrx   strr   
differencero   r   r   r   )rX   rY   rH   rI   rJ   left_byright_byr   rN   rR   checkr   _r   s     ```  ```   @r]   merge_orderedr   +  s   P  x3EFFgs##iGG''5u:?eW$>?@@&we=WX	 M 
	h$$ zHH((7u:?eW$?@AA&T#=
	
 M %Mr_   c                P    [        U UUUUUUUUU	U
SUUUS9nUR                  5       $ )aH  
Perform a merge by key distance.

This is similar to a left-join except that we match on nearest
key rather than equal keys. Both DataFrames must be sorted by the key.

For each row in the left DataFrame:

  - A "backward" search selects the last row in the right DataFrame whose
    'on' key is less than or equal to the left's key.

  - A "forward" search selects the first row in the right DataFrame whose
    'on' key is greater than or equal to the left's key.

  - A "nearest" search selects the row in the right DataFrame whose 'on'
    key is closest in absolute distance to the left's key.

Optionally match on equivalent keys with 'by' before searching with 'on'.

Parameters
----------
left : DataFrame or named Series
right : DataFrame or named Series
on : label
    Field name to join on. Must be found in both DataFrames.
    The data MUST be ordered. Furthermore this must be a numeric column,
    such as datetimelike, integer, or float. On or left_on/right_on
    must be given.
left_on : label
    Field name to join on in left DataFrame.
right_on : label
    Field name to join on in right DataFrame.
left_index : bool
    Use the index of the left DataFrame as the join key.
right_index : bool
    Use the index of the right DataFrame as the join key.
by : column name or list of column names
    Match on these columns before performing merge operation.
left_by : column name
    Field names to match on in the left DataFrame.
right_by : column name
    Field names to match on in the right DataFrame.
suffixes : 2-length sequence (tuple, list, ...)
    Suffix to apply to overlapping column names in the left and right
    side, respectively.
tolerance : int or Timedelta, optional, default None
    Select asof tolerance within this range; must be compatible
    with the merge index.
allow_exact_matches : bool, default True

    - If True, allow matching with the same 'on' value
      (i.e. less-than-or-equal-to / greater-than-or-equal-to)
    - If False, don't match the same 'on' value
      (i.e., strictly less-than / strictly greater-than).

direction : 'backward' (default), 'forward', or 'nearest'
    Whether to search for prior, subsequent, or closest matches.

Returns
-------
DataFrame

See Also
--------
merge : Merge with a database-style join.
merge_ordered : Merge with optional filling/interpolation.

Examples
--------
>>> left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]})
>>> left
    a left_val
0   1        a
1   5        b
2  10        c

>>> right = pd.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]})
>>> right
   a  right_val
0  1          1
1  2          2
2  3          3
3  6          6
4  7          7

>>> pd.merge_asof(left, right, on="a")
    a left_val  right_val
0   1        a          1
1   5        b          3
2  10        c          7

>>> pd.merge_asof(left, right, on="a", allow_exact_matches=False)
    a left_val  right_val
0   1        a        NaN
1   5        b        3.0
2  10        c        7.0

>>> pd.merge_asof(left, right, on="a", direction="forward")
    a left_val  right_val
0   1        a        1.0
1   5        b        6.0
2  10        c        NaN

>>> pd.merge_asof(left, right, on="a", direction="nearest")
    a left_val  right_val
0   1        a          1
1   5        b          6
2  10        c          7

We can use indexed DataFrames as well.

>>> left = pd.DataFrame({"left_val": ["a", "b", "c"]}, index=[1, 5, 10])
>>> left
   left_val
1         a
5         b
10        c

>>> right = pd.DataFrame({"right_val": [1, 2, 3, 6, 7]}, index=[1, 2, 3, 6, 7])
>>> right
   right_val
1          1
2          2
3          3
6          6
7          7

>>> pd.merge_asof(left, right, left_index=True, right_index=True)
   left_val  right_val
1         a          1
5         b          3
10        c          7

Here is a real-world times-series example

>>> quotes = pd.DataFrame(
...     {
...         "time": [
...             pd.Timestamp("2016-05-25 13:30:00.023"),
...             pd.Timestamp("2016-05-25 13:30:00.023"),
...             pd.Timestamp("2016-05-25 13:30:00.030"),
...             pd.Timestamp("2016-05-25 13:30:00.041"),
...             pd.Timestamp("2016-05-25 13:30:00.048"),
...             pd.Timestamp("2016-05-25 13:30:00.049"),
...             pd.Timestamp("2016-05-25 13:30:00.072"),
...             pd.Timestamp("2016-05-25 13:30:00.075")
...         ],
...         "ticker": [
...                "GOOG",
...                "MSFT",
...                "MSFT",
...                "MSFT",
...                "GOOG",
...                "AAPL",
...                "GOOG",
...                "MSFT"
...            ],
...            "bid": [720.50, 51.95, 51.97, 51.99, 720.50, 97.99, 720.50, 52.01],
...            "ask": [720.93, 51.96, 51.98, 52.00, 720.93, 98.01, 720.88, 52.03]
...     }
... )
>>> quotes
                     time ticker     bid     ask
0 2016-05-25 13:30:00.023   GOOG  720.50  720.93
1 2016-05-25 13:30:00.023   MSFT   51.95   51.96
2 2016-05-25 13:30:00.030   MSFT   51.97   51.98
3 2016-05-25 13:30:00.041   MSFT   51.99   52.00
4 2016-05-25 13:30:00.048   GOOG  720.50  720.93
5 2016-05-25 13:30:00.049   AAPL   97.99   98.01
6 2016-05-25 13:30:00.072   GOOG  720.50  720.88
7 2016-05-25 13:30:00.075   MSFT   52.01   52.03

>>> trades = pd.DataFrame(
...        {
...            "time": [
...                pd.Timestamp("2016-05-25 13:30:00.023"),
...                pd.Timestamp("2016-05-25 13:30:00.038"),
...                pd.Timestamp("2016-05-25 13:30:00.048"),
...                pd.Timestamp("2016-05-25 13:30:00.048"),
...                pd.Timestamp("2016-05-25 13:30:00.048")
...            ],
...            "ticker": ["MSFT", "MSFT", "GOOG", "GOOG", "AAPL"],
...            "price": [51.95, 51.95, 720.77, 720.92, 98.0],
...            "quantity": [75, 155, 100, 100, 100]
...        }
...    )
>>> trades
                     time ticker   price  quantity
0 2016-05-25 13:30:00.023   MSFT   51.95        75
1 2016-05-25 13:30:00.038   MSFT   51.95       155
2 2016-05-25 13:30:00.048   GOOG  720.77       100
3 2016-05-25 13:30:00.048   GOOG  720.92       100
4 2016-05-25 13:30:00.048   AAPL   98.00       100

By default we are taking the asof of the quotes

>>> pd.merge_asof(trades, quotes, on="time", by="ticker")
                     time ticker   price  quantity     bid     ask
0 2016-05-25 13:30:00.023   MSFT   51.95        75   51.95   51.96
1 2016-05-25 13:30:00.038   MSFT   51.95       155   51.97   51.98
2 2016-05-25 13:30:00.048   GOOG  720.77       100  720.50  720.93
3 2016-05-25 13:30:00.048   GOOG  720.92       100  720.50  720.93
4 2016-05-25 13:30:00.048   AAPL   98.00       100     NaN     NaN

We only asof within 2ms between the quote time and the trade time

>>> pd.merge_asof(
...     trades, quotes, on="time", by="ticker", tolerance=pd.Timedelta("2ms")
... )
                     time ticker   price  quantity     bid     ask
0 2016-05-25 13:30:00.023   MSFT   51.95        75   51.95   51.96
1 2016-05-25 13:30:00.038   MSFT   51.95       155     NaN     NaN
2 2016-05-25 13:30:00.048   GOOG  720.77       100  720.50  720.93
3 2016-05-25 13:30:00.048   GOOG  720.92       100  720.50  720.93
4 2016-05-25 13:30:00.048   AAPL   98.00       100     NaN     NaN

We only asof within 10ms between the quote time and the trade time
and we exclude exact matches on time. However *prior* data will
propagate forward

>>> pd.merge_asof(
...     trades,
...     quotes,
...     on="time",
...     by="ticker",
...     tolerance=pd.Timedelta("10ms"),
...     allow_exact_matches=False
... )
                     time ticker   price  quantity     bid     ask
0 2016-05-25 13:30:00.023   MSFT   51.95        75     NaN     NaN
1 2016-05-25 13:30:00.038   MSFT   51.95       155   51.97   51.98
2 2016-05-25 13:30:00.048   GOOG  720.77       100     NaN     NaN
3 2016-05-25 13:30:00.048   GOOG  720.92       100     NaN     NaN
4 2016-05-25 13:30:00.048   AAPL   98.00       100     NaN     NaN
asof)rH   rI   rJ   rK   rL   r   r   r   rN   rR   	toleranceallow_exact_matches	direction)
_AsOfMergerW   )rX   rY   rH   rI   rJ   rK   rL   r   r   r   rN   r   r   r   r\   s                  r]   
merge_asofr     sJ    v 
/
B" ==?r_   c                  v   \ rS rSr% SrSrS\S'   S\S'   S\S	'   S\S
'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'   S\S'             S.                         S/S jjr      S0S jrS1S jr	\
          S2S j5       rS3S4S  jjr\
\S5S! j5       5       r\
      S6S" j5       r\
S7S# j5       r\
S8S$ j5       r\
        S9S% j5       r  S:S& jr\
  S;S' j5       r\
 S<         S=S( jj5       r\
  S>S) j5       r\
S?S* j5       rS+ r\
S@S, j5       rS-rg)ArV   i  z
Perform a database (SQL) merge operation between two DataFrame or Series
objects using either columns as keys or their row indexes
r^   JoinHow | Literal['asof']rR   IndexLabel | NonerH   z!Sequence[Hashable | AnyArrayLike]rI   rJ   boolrK   rL   rM   r   rN   rQ   
str | boolrO   
str | NonerP   zlist[Hashable]
join_nameslist[ArrayLike]right_join_keysleft_join_keysNc                ^   [        U5      n[        U5      nU=U l        U l        U=U l        U l        X0l        [        R                  " U5      U l        Xl	        U	=(       d    US:H  U l
        Xpl        Xl        Xl        [        U5      (       d  [        S[!        U5       35      e[        U5      (       d  [        S[!        U5       35      eUR"                  R$                  UR"                  R$                  :w  a<  SUR"                  R$                   SUR"                  R$                   S3n['        U5      eU R)                  XV5      u  U l        U l        U R/                  5       u  U l        U l        U l        nnU(       a   U R                  R7                  U5      U l        U(       a   U R                  R7                  U5      U l        U R9                  U R0                  U R2                  5        U R;                  U R0                  5        U R=                  5         Ub  U R?                  U5        g g )Nouterz/left_index parameter must be of type bool, not z0right_index parameter must be of type bool, not z0Not allowed to merge between different levels. (z levels on the left, z on the right)) rT   rX   	orig_leftrY   
orig_rightrR   commaybe_make_listrH   rN   rM   rK   rL   rO   r!   r   typero   nlevelsr   _validate_left_right_onrI   rJ   _get_merge_keysr   r   r   _drop_labels_or_levels_maybe_require_matching_dtypes_validate_tolerance_maybe_coerce_merge_keys_validate_validate_kwd)selfrX   rY   rR   rH   rI   rJ   rK   rL   rM   rN   rO   rP   _left_rightmsg	left_drop
right_drops                     r]   __init___MergeOperation.__init__  s    "$'"5)%**	DN'--
T_%%b) *C7N	$&"z""A$zBRAST  {##B4CTBUV 
 ==  FNN$:$::MM))**?>>))*.: 
 S/!&*&B&B7&U#dm   "	
 O 		88CDI:::FDJ++D,?,?AUAUV  !4!45 	%%'
 ''1  r_   c                    g rm   rd   )r   r   r   s      r]   r   ._MergeOperation._maybe_require_matching_dtypes/  s     	r_   c                    g rm   rd   )r   r   s     r]   r   #_MergeOperation._validate_tolerance5  s    r_   c           
     f   U R                   SS nU R                  SS n[        U R                   R                  U R                  R                  U R                  5      u  pxUbR  [        U[        U5      5      (       d8  UR                  R                  UUSSSSSS9n	UR                  XR                  S9nXl        UbR  [        U[        U5      5      (       d8  UR                  R                  UUSSSSSS9n
UR                  XR                  S9nXl        SSKJn  Xul        Xl        U" XV/SUS	9nU$ )
z/
reindex along index and concat along columns.
Nrb   FT)rt   rQ   
only_slice
allow_dupsuse_na_proxy)axesr   ru   )rt   rQ   )rX   rY   _items_overlap_with_suffix
_info_axisrN   r   r   _mgrreindex_indexer_constructor_from_mgrr   r   pandasrv   ro   )r   
join_indexleft_indexerright_indexerrQ   rX   rY   llabelsrlabelslmgrrmgrrv   r   s                r]   _reindex_and_concat#_MergeOperation._reindex_and_concat9  s=    yy|

15II  $**"7"7
 #,<\3t9,U,U 99,,! - D --d-CD
$-=3u:.
 .
 ::--! . D //99/EE !AD9r_   c                   U R                   (       a3  U R                  U R                  U R                  5      u  U l        U l        U R	                  5       u  p#nU R                  X#XAS9nUR                  X R                  S9nU R                   (       a  U R                  U5      nU R                  XSU5        U R                  U5        UR                  U SS9$ )NrS   )methodr^   )rO   _indicator_pre_mergerX   rY   _get_join_infor   __finalize___merge_type_indicator_post_merge_maybe_add_join_keys_maybe_restore_index_levels)r   rQ   r   r   r   r   s         r]   rW   _MergeOperation.get_resultr  s    >>$($=$=dii$T!DItz262E2E2G/
-))m * 
 $$T2B2B$C>>//7F!!&F((0""4"88r_   c                    [        U R                  [        5      (       a  U R                  $ [        U R                  [        5      (       a  U R                  (       a  S$ S $ [	        S5      e)N_mergez<indicator option can only accept boolean or string arguments)rx   rO   r   r   r   r   s    r]   _indicator_name_MergeOperation._indicator_name  sQ     dnnc**>>!--#~~8747N r_   c                p   UR                   R                  UR                   5      nS H  nXC;   d  M
  [        SU 35      e   U R                  U;   a  [        S5      eUR	                  5       nUR	                  5       nSUS'   US   R                  S5      US'   SUS'   US   R                  S5      US'   X4$ )	N)_left_indicator_right_indicatorzECannot use `indicator=True` option when data contains a column named z:Cannot use name of an existing column for indicator columnrb   r   int8   r   )ro   unionr   r   rQ   astype)r   rX   rY   ro   is        r]   r   $_MergeOperation._indicator_pre_merge  s     ,,$$U]]38A| 44538  9 7*L  yy{

"#"&'8"9"@"@"H$% !$)*<$=$D$DV$L !{r_   c                4   US   R                  S5      US'   US   R                  S5      US'   [        US   US   -   / SQS9XR                  '   UU R                     R                  R	                  / SQ5      XR                  '   UR                  SS/SS9nU$ )	Nr   r   r   )rb   r     )
categories)	left_only
right_onlybothrb   )labelsrt   )fillnar3   r   catrename_categoriesdrop)r   r   s     r]   r   %_MergeOperation._indicator_post_merge  s    $*+<$=$D$DQ$G !%+,>%?%F%Fq%I!"'2%&0B)CC (
##$ (.  (

# CD 	##$ %68J$KRSTr_   c                   / n[        U R                  U R                  U R                  5       H}  u  p4nU R                  R                  U5      (       d  M(  U R                  R                  U5      (       d  MJ  XE:X  d  MQ  X1R                  R                  ;  d  Ml  UR                  U5        M     U(       a  UR                  USS9  gg)a  
Restore index levels specified as `on` parameters

Here we check for cases where `self.left_on` and `self.right_on` pairs
each reference an index level in their respective DataFrames. The
joined columns corresponding to these pairs are then restored to the
index of `result`.

**Note:** This method has side effects. It modifies `result` in-place

Parameters
----------
result: DataFrame
    merge result

Returns
-------
None
TinplaceN)zipr   rI   rJ   r   _is_level_referencer   r   namesr   	set_index)r   r   names_to_restorenameleft_key	right_keys         r]   r   +_MergeOperation._maybe_restore_index_levels  s    * ),OOT\\4==*
%DI 228<< OO77  ) 2 22 ''-#*
& -t< r_   c                   S nS n[        S U R                   5       5      (       d   e[        U R                  U R                  U R
                  5      n[        U5       GH  u  nu  pn
[        X5      (       d  M  Su  pX;   Ga  Uc  UGb  XR                  ;   at  Uc  Uc  SOUS:H  R                  5       nU(       aQ  U R                  U   nX   R                  U R                  U   R                  :w  a  U R                  U   R                  nOXR                  ;   as  Uc  Uc  SOUS:H  R                  5       nU(       aQ  U R                  U   nX   R                  U R                  U   R                  :w  a  U R                  U   R                  nOU R                  U   nU R                  U   nUc  Uc  GMZ  Uc  X   R                  nO:Uc  UnO4[        USS9n[        UR                  5      n[         R"                  " XUS9nUc  X   R                  nO;Uc  UnO5[        USS9n[        UR                  5      n[         R"                  " UUUS9nUb0  US:H  R                  5       (       a  [%        U5      nUR                  nOUb0  US:H  R                  5       (       a  [%        U5      nUR                  nO[%        U5      nUb  US:H  nUR'                  U) U5      n[)        UR                  UR                  /5      nUR                  R*                  S:X  a6  UR                  R*                  S:X  a  UR*                  S	:X  a  UR                  nUR-                  U5      (       a   UR/                  UUUR0                  S
9X'   GM&  UR3                  U5      (       a  [5        UR0                  [6        5      (       aa  UUl        UR0                  R:                   Vs/ s H&  nUU:w  a  UR0                  R=                  U5      OUPM(     nnUR?                  USS9  GM  [%        UUS9Ul        GM  URA                  Xx=(       d    SU 3U5        GM     g s  snf )Nc              3  B   #    U  H  n[        U[        5      v   M     g 7frm   )rx   _knownrp   r   s     r]   rr   7_MergeOperation._maybe_add_join_keys.<locals>.<genexpr>  s     F2EQ:a((2Es   )NNFTextract_numpy
fill_valueMO)dtyper   r  )r  key_)!r{   r   r  r   rI   rJ   	enumerate_should_fillrX   anyr   r*  _valuesrY   r<   r1   algostake_ndr4   wherer   kind_is_label_reference_constructor_slicedr   r  rx   r5   r  r  get_level_valuesr  insert)r   r   r   r   left_has_missingright_has_missingkeysr  r  lnamername	take_left
take_rightlvalslfillrvalstakerrfillkey_colresult_dtype	mask_left
level_nameidx_lists                          r]   r   $_MergeOperation._maybe_add_join_keys  s	      F$2E2EFFFFF4??DLL$--@'0#A#U--$.!I~+}/Hyy(+3 $0#7 !&&2b&8%=%=%? - ,)-)=)=a)@J%|11TYYt_5J5JJ,0IIdO,C,C	+,4 $1#8 !&&3r&9%>%>%@ . -(,(;(;A(>I%|11TZZ5E5K5KK-1ZZ-=-E-E
 !//2	!11!4
$
(>$"L00E!)%E !.it LI.y?E!MM)eTE%"L00E"*&E **DIE.u{{;E!MM%5QE  +1C0H0H0J0J#ElG#(;;L".MR4G3L3L3N3N#ElG#(;;L#ElG#/$0B$6	")--
E"B#3U[[%++4N#OL((C/!KK,,3(--4 (/}}--d33#)#=#=|6<< $> $FL //55!&,,
;;'+
 /5ll.@.@	$ /A
  *T1 #LL99*E!() /A	 ! $ ((4(@',W4'@MM!%7tA3ZAM (7v$s   -Qc                    U R                   S:w  d   e[        U R                  U R                  U R                  U R                   S9$ )return the join indexersr   )rM   rR   )rR   get_join_indexersr   r   rM   r   s    r]   _get_join_indexers"_MergeOperation._get_join_indexers_  s@    
 xx6!!! !5!5DII488
 	
r_   c                l   U R                   R                  nU R                  R                  nU R                  (       aK  U R                  (       a:  U R
                  S:w  a*  UR                  X R
                  SU R                  S9u  p4nGOU R                  (       a4  U R
                  S:X  a$  [        XU R                  U R                  S9u  p4nGOdU R                  (       a4  U R
                  S:X  a$  [        X!U R                  U R                  S9u  p5nGOU R                  5       u  pEU R                  (       aR  [        U R                   5      S:  a  U R                  UUUSS9nOUc  UR                  5       nOUR                  U5      nOU R                  (       au  U R
                  S:X  a  U R                  UUUSS9nOv[        U R                  5      S:  a  U R                  UUUSS9nOJUc  UR                  5       nO6UR                  U5      nO$Uc  [        U5      O
[        U5      n[!        U5      nX4U4$ )	Nr   TrR   return_indexersrM   rX   rk   rY   r   rR   )rX   r   rY   rK   rL   rR   r   rM   _left_join_on_indexr   r   rM  r   _create_join_indexrQ   r   r>   )r   left_axright_axr   r   r   ns          r]   r   _MergeOperation._get_join_infoi  s    ))//::##??t//DHH4F6=llhh499 7C 73Jm $((f"46I4#6#6TYY73Jm __W!46I4#7#7dii73J| -1,C,C,E)\tyy>A%!%!8!8 $#	 "9 "J #*!)J!)}!=J88v%!%!8!8 $"	 "9 "J _q(!%!8!8 %"	 "9 "J ")!(J!(l!;J$0$8CLc,>O*1-
66r_   c                6   U R                   US4;   ad  [        U[        5      (       dO  US:H  n[        R                  " U5      (       a/  [        UR                  SS9nUR                  [        U/5      5      nUc  UR                  5       $ UR                  U5      $ )ae  
Create a join index by rearranging one index to match another

Parameters
----------
index : Index
    index being rearranged
other_index : Index
    used to supply values not found in index
indexer : np.ndarray[np.intp] or None
    how to rearrange index
how : str
    Replacement is only necessary if indexer based on other_index.

Returns
-------
Index
r   r#  F)compat)rR   rx   r5   npr.  r1   r*  r   r4   rQ   r   )r   r   other_indexindexerrR   maskr'  s          r]   rT  "_MergeOperation._create_join_index  s}    4 88W~%jj.Q.Q b=Dvvd||/EJ
UJ<%89?::<zz'""r_   c                  ^^ / n/ n/ n/ n/ nU R                   U R                  smmU4S jnU4S jn[        U R                  5      (       Ga  [        U R                  5      (       Gau  [        U R                  U R                  5       GHN  u  p[        USS9n[        U	SS9n	U" U5      (       a  [        [        U5      nUR                  U5        U" U	5      (       a4  [        [        U	5      n	UR                  U	5        UR                  S5        M  [        [        U	5      n	U	b3  UR                  TR                  U	5      5        UR                  U	5        M  UR                  TR                  R                  5        UR                  TR                  R                  5        GM  U" U	5      (       ds  [        [        U	5      n	U	b!  UR                  TR                  U	5      5        O%UR                  TR                  R                  5        Ub  X:X  a  UR                  U	5        O![        [        U	5      n	UR                  U	5        UbD  [        [        U5      nUR                  TR                  U5      5        UR                  U5        GM  UR                  TR                  R                  5        UR                  TR                  R                  5        GMQ     GO[        U R                  5      (       Gab  U R                   H  n
U" U
5      (       a>  [        U
SS9n
[        [        U
5      n
UR                  U
5        UR                  S5        MN  [        [        U
5      n
UR                  TR                  U
5      5        UR                  U
5        M     [        U R                  R                  [         5      (       aw  [        U R                  R                  R"                  U R                  R                  R$                  5       VVs/ s H   u  pUR                  R'                  U5      PM"     nnnGOU R                  R                  R                  /nGOz[        U R                  5      (       Ga_  U R                   H  n
[        U
SS9n
U" U
5      (       a4  [        [        U
5      n
UR                  U
5        UR                  S5        MN  [        [        U
5      n
UR                  TR                  U
5      5        UR                  U
5        M     [        U R                   R                  [         5      (       av  [        U R                   R                  R"                  U R                   R                  R$                  5       VVs/ s H   u  pUR                  R'                  U5      PM"     nnnO!U R                   R                  R                  /nXX5U4$ s  snnf s  snnf )zJ
Returns
-------
left_keys, right_keys, join_names, left_drop, right_drop
c                `   > [        U [        5      =(       a    [        U 5      [        T5      :H  $ rm   rx   r   r   )r   rX   s    r]   r   1_MergeOperation._get_merge_keys.<locals>.<lambda>  s!    Jq&1Ic!fD	6IIr_   c                `   > [        U [        5      =(       a    [        U 5      [        T5      :H  $ rm   rb  )r   rY   s    r]   r   rc    s!    Jq&1Jc!fE
6JJr_   Tr$  N)rX   rY   _anyrI   rJ   r  r<   r	   r   r   r   _get_label_or_level_valuesr   r/  r  rx   r5   levelscodesr   )r   	left_keys
right_keysr   r   r   is_lkeyis_rkeylkrkklev	lev_codesrX   rY   s                @@r]   r   _MergeOperation._get_merge_keys  s    &(	&(
%'
%'
$&	iieIJ $t}}"5"5dllDMM:"2T:"2T:2;;i,B$$R(r{{!)R0"))"-"))$/ "(B/>&--e.N.Nr.RS&--b1 '--ekk.A.AB&--ekk.>.>?"2;; "(B/>&--e.N.Nr.RS '--ekk.A.AB>bh&--b1!)R0"))"-~ "(B/!(()H)H)LM"))"- "((););<"))$**//:[ ;\ $,,\\1::%at<AY*A$$Q'%%d+ Xq)A$$T%D%DQ%GH%%a( " $****J77 +.

((//1A1A1G1G++ KK$$Y/+  
 #jj..667
$--  ]]!!481::Y*A%%a(%%d+ Xq)A%%e&F&Fq&IJ%%a( # $))//:66 +.		..		0E0E++ KK$$Y/+  	 "YY__445	jZGG?,s   'W'Wc                   [        U R                  U R                  U R                  5       G	H%  u  pn[	        U5      (       a  [	        U5      (       a   [	        U5      (       d  [	        U5      (       a  MI  [        USS9n[        USS9n[        UR                  [        5      n[        UR                  [        5      n[        UR                  5      =(       d    [        UR                  5      n[        UR                  5      =(       d    [        UR                  5      nU(       aA  U(       a:  [        [        U5      n[        [        U5      nUR                  U5      (       a  GM:  O,U(       d  U(       a  OUR                  UR                  :X  a  GMg  SUR                   SUR                   SU S3n[        UR                  5      (       Ga3  [        UR                  5      (       Ga  UR                  R                  UR                  R                  :X  a  GM  [        UR                  [         5      (       a  [        UR                  [         5      (       di  [#        UR                  UR                  /5      n	[        U	[         5      (       a!  U	R%                  5       n
U
R'                  X)SS9nOUR)                  U	5      nO[        UR                  [         5      (       ah  [#        UR                  UR                  /5      n	[        U	[         5      (       a!  U	R%                  5       n
U
R'                  XSS9nOUR)                  U	5      n[+        UR                  5      (       a  [-        UR                  5      (       a  [.        R0                  " S	S
9   UR)                  UR                  5      nS S S 5        [.        R2                  " U5      ) nUW:H  nX   R5                  5       (       d"  [6        R8                  " S[:        [=        5       S9  GM  [-        UR                  5      (       a  [+        UR                  5      (       a  [.        R0                  " S	S
9   UR)                  UR                  5      nS S S 5        [.        R2                  " U5      ) nUW:H  nX   R5                  5       (       d"  [6        R8                  " S[:        [=        5       S9  GM  [>        R@                  " USS9[>        R@                  " USS9:X  a  GM  GO%U(       a  [C        UR                  5      (       d!  [C        UR                  5      (       a	  U(       a  GOU(       a  [        UR                  5      (       d!  [        UR                  5      (       al  U(       ae  [>        R@                  " USS9n[>        R@                  " USS9n/ SQn/ SQnUU;   a  UU;   a  GO_UU;   a  UU;  d  UU;   a  UU;  a  [E        U5      eGO:[G        UR                  5      (       a%  [G        UR                  5      (       d  [E        U5      e[G        UR                  5      (       d%  [G        UR                  5      (       a  [E        U5      e[        UR                  [H        5      (       a*  [        UR                  [H        5      (       d  [E        U5      e[        UR                  [H        5      (       d*  [        UR                  [H        5      (       a  [E        U5      e[        UR                  [H        5      (       a  [        UR                  [H        5      (       d4  UR                  R                  S:X  a  UR                  R                  S:X  a  GME  UR                  R                  S:X  a%  UR                  R                  S:X  a  [E        U5      eUR                  R                  S:X  a%  UR                  R                  S:X  a  [E        U5      e[        UR                  5      (       a  [        UR                  5      (       a  GM  X0RJ                  RL                  ;   a{  U(       a$  [        [        U5      RN                  R                  O[P        nU RJ                  RS                  5       U l%        U RJ                  U   R)                  U5      U RJ                  U'   X0RT                  RL                  ;   d  GM  U(       a$  [        [        U5      RN                  R                  O[P        nU RT                  RS                  5       U l*        U RT                  U   R)                  U5      U RT                  U'   G	M(     g ! , (       d  f       GN= f! , (       d  f       GN = f)NTr$  zYou are trying to merge on  and z columns for key 'z2'. If you wish to proceed you should use pd.concatFr*  rQ   ignore)invalidzjYou are merging on int and float columns where the float values are not equal to their int representation.)
stacklevel)skipna)integerzmixed-integerbooleanempty)stringunicodemixedbytesr|  r(  m)+r  r   r   r   r   r<   rx   r*  r,   r)   r*   r	   r3   #_categories_match_up_to_permutationr(   r3  r   r   construct_array_type_from_sequencer  r%   r#   r[  errstateisnanr{   warningswarnUserWarningr   r   infer_dtyper"   r   r+   r-   rX   ro   r  objectrQ   rY   )r   rm  rn  r  	lk_is_cat	rk_is_catlk_is_object_or_stringrk_is_object_or_stringr   ctcom_clscastedr^  matchinferred_leftinferred_right
bool_typesstring_typestyps                      r]   r   (_MergeOperation._maybe_coerce_merge_keysS  s     !5!5t
LBD BBRSWWr6Br6B"288-=>I"288-=>I%4RXX%> &/C" &5RXX%> &/C" Y+r*+r*99"== > iRXX% .bhhZuRXXJ G 6!SU   )).>rxx.H.H88==BHHMM1bhh77
HHnA A *288RXX*>?B!"n55"$"9"9";$33Bu3MYYr].99)288RXX*>?B!"n55"$"9"9";$33Bu3MYYr] $BHH--.2J2JX6 "$288!4	 7 HHRL=D&LE ;??,, I ('7'9 !"((++0@0J0JX6 "$288!4	 7 HHRL=D&LE ;??,, I ('7'9  ??2e4u9   )]288-D-Dbhh'',B )-=bhh-G-G **/E #5 A!$E!BM
O !J.>Z3O "\1nL6X"l2}L7X$S/) %RXX..7J2887T7T o%(227J2887T7T o%BHHo66z/@ @ !o%/::z/@ @ !o%288_55rxx99((--3&288==C+?#%"((--3*> o%#%"((--3*> o% **rxx/H/H yy(((@Id;+66<<v IINN,	"&))D/"8"8"=		$zz)))@Id;+66<<v!ZZ__.
#'::d#3#:#:3#?

4 k
B 76( 76s   ee)
e&	)
e8	c           
     J   [         R                  " U5      n[         R                  " U5      nU R                  Gc9  UGc5  UGc1  U R                  (       a  U R                  (       a  Su  pGOU R                  (       a  [        S5      eU R                  (       a  [        S5      eU R                  R                  nU R                  R                  nUR                  U5      n[        U5      S:X  a+  [        SU SU SU R                   SU R                   35      eUR                  US	S
9R                  (       a  UR                  US	S
9R                  (       d  [        S[        U5       35      eU=pGOU R                  bM  Uc  Ub  [        S5      eU R                  (       d  U R                  (       a  [        S5      eU R                  =pGO1Ub  U R                  (       a  [        S5      eU R                  (       d  Uc  [        S5      e[        U5      nU R                  (       a>  [        U5      U R                  R                  R                  :w  a  [!        S5      eS /U-  nOUb  U R                  (       a  [        S5      eU R                  (       d  Uc  [        S5      e[        U5      nU R                  (       a>  [        U5      U R                  R                  R                  :w  a  [!        S5      eS /U-  n[        U5      [        U5      :w  a  [!        S5      eX4$ )N)rd   rd   z&Must pass right_on or right_index=Truez$Must pass left_on or left_index=Truer   z>No common columns to perform merge on. Merge options: left_on=z, right_on=z, left_index=z, right_index=rc   rR  zData columns not unique: zSCan only pass argument "on" OR "left_on" and "right_on", not a combination of both.zYCan only pass argument "on" OR "left_index" and "right_index", not a combination of both.z:Can only pass argument "left_on" OR "left_index" not both.z&Must pass "right_on" OR "right_index".zDlen(left_on) must equal the number of levels in the index of "right"z<Can only pass argument "right_on" OR "right_index" not both.z$Must pass "left_on" OR "left_index".zDlen(right_on) must equal the number of levels in the index of "left"z%len(right_on) must equal len(left_on))r   r   rH   rK   rL   r   rX   ro   rY   intersectionr   r   	is_uniquereprr   r   r   )r   rI   rJ   	left_cols
right_colscommon_colsrW  s          r]   r   '_MergeOperation._validate_left_right_on  s   %%g.&&x0 77?w83C4#3#3$*! !IJJ!! !GHH !II--	!ZZ//
'44Z@{#q($229 ;$$,: .&&*oo%6 7''+'7'7&8	:  "{@JJ%??;G?DNN$'@kAR@S%TUU%00(WW "h&: A  $"2"2 D  "&(Gh  P  ##(8 !IJJGAw<4::#3#3#;#;;$<  !6A:! R  ??w !GHHHAx=DIIOO$;$;;$;   &1*x=CL(DEE  r_   c                   U R                   (       a!  U R                  R                  R                  nO*[        R
                  " U R                  5      R                  nU R                  (       a!  U R                  R                  R                  nO*[        R
                  " U R                  5      R                  nUS;   a>  U(       d  U(       d  [        S5      eU(       d  [        S5      eU(       d  [        S5      eg US;   a  U(       d  [        S5      eg US;   a  U(       d  [        S5      eg US	;   a  g [        S
U S35      e)N)
one_to_onez1:1zQMerge keys are not unique in either left or right dataset; not a one-to-one mergezAMerge keys are not unique in left dataset; not a one-to-one mergezBMerge keys are not unique in right dataset; not a one-to-one merge)one_to_manyz1:mzBMerge keys are not unique in left dataset; not a one-to-many merge)many_to_onezm:1zCMerge keys are not unique in right dataset; not a many-to-one merge)many_to_manyzm:m"z" is not a valid argument. Valid arguments are:
- "1:1"
- "1:m"
- "m:1"
- "m:m"
- "one_to_one"
- "one_to_many"
- "many_to_one"
- "many_to_many")rK   r   r   r  r5   from_arraysr   rL   r   r   r   r   )r   rP   left_uniqueright_uniques       r]   r   &_MergeOperation._validate_validate_kwd`  s=    ??....88K$001D1DEOOK??00::L%11$2F2FGQQL ,,| ?   W    X   
 // X  
 // .    00 H: 	# 	# r_   )rR   rO   r   rX   rK   r   rI   rH   r   r   rY   rL   r   rJ   rM   rN   )
rc   NNNFFT_x_yFN)rX   DataFrame | SeriesrY   r  rR   r   rH    IndexLabel | AnyArrayLike | NonerI   r  rJ   r  rK   r   rL   r   rM   r   rN   r   rO   r   rP   r   r   Noner   r   r   r   r   r  r   r   r   r  )
r   r4   r   npt.NDArray[np.intp] | Noner   r  rQ   bool | Noner   rA   TrQ   r  r   rA   )r   r   )rX   rA   rY   rA   r   ztuple[DataFrame, DataFrame])r   rA   r   rA   )r   rA   r   r  )r   rA   r   r  r   r  r   r  )r   ?tuple[npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None])r   zFtuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None])rX   )
r   r4   r\  r4   r]  r  rR   r   r   r4   )r   zWtuple[list[ArrayLike], list[ArrayLike], list[Hashable], list[Hashable], list[Hashable]])r   r  )rP   r   r   r  )__name__
__module____qualname____firstlineno____doc__r   __annotations__r   r   r   r
   r   rW   r   r   r   r   r   r   rM  r   rT  r   r   r   r   __static_attributes__rd   r_   r]   rV   rV     s   
 K	"" /.//
J
J$$## *1/34859 !) %#L2 L2 "L2 '	L2
 -L2 2L2 3L2 L2 L2 L2 L2 L2 L2 
L2\-@O	 66 26 3	6
 6 
6 6p9(    &/	$ 6   )= )=V rBrB 2rB 3	rB
 
rB rBh
	H
 <7	O<7 <7|  %#%# %# -	%#
 %# 
%# %#N @H
@H @HD |@ |@|L!\ 8 8r_   rV   c                  ^ ^^ [        T 5      [        T5      :X  d   S5       e[        T S   5      n[        TS   5      nUS:X  a*  US;   a
  [        5       $ T(       d  US;   a  [        US5      $ O/US:X  a)  US;   a
  [        5       $ T(       d  US;   a  [        US5      $ [        T 5      S	:  aM  U UU4S
 j[        [        T 5      5       5       n[	        U6 nS U 5       u  pn
[        X[        U
5      T5      u  pO
T S   nTS   n[        U5      n[        U5      nUR                  (       aI  UR                  (       a8  UR                  (       d  UR                  (       a  UR                  XSTS9u  nnnO%[        UR                  UR                  TU5      u  nnUb  [        U[        U5      5      (       a  SnUb  [        U[        U5      5      (       a  SnUU4$ )ak  

Parameters
----------
left_keys : list[ndarray, ExtensionArray, Index, Series]
right_keys : list[ndarray, ExtensionArray, Index, Series]
sort : bool, default False
how : {'inner', 'outer', 'left', 'right'}, default 'inner'

Returns
-------
np.ndarray[np.intp] or None
    Indexer into the left_keys.
np.ndarray[np.intp] or None
    Indexer into the right_keys.
z0left_keys and right_keys must be the same lengthr   )rX   rc   )rY   r   T)rY   rc   )rX   r   Frb   c              3  F   >#    U  H  n[        TU   TU   TS 9v   M     g7frk   N)_factorize_keys)rp   rW  ri  rj  rM   s     r]   rr   $get_join_indexers.<locals>.<genexpr>  s)      
* IaL*Q-dC*s   !c              3  8   #    U  H  n[        U5      v   M     g 7frm   ry   r!  s     r]   rr   r         5fT!WWf   rP  N)r   _get_empty_indexer _get_no_sort_one_missing_indexerr   r  _get_join_keysrz   r4   is_monotonic_increasingr  r   get_join_indexers_non_uniquer/  r   )ri  rj  rM   rR   left_nright_nmappedzippedllabrlabshapelkeyrkeyrX   rY   r   lidxridxs   ```               r]   rL  rL    s   , y>S  :9: 
 1F*Q- G{##%''#!333GTBB	A$$%''#!223FEBB 9~
3y>*
 f5f5E $DedC
d|!};D$KE 	$$))^^u		%$T	R41LL%--s

d ,T3t9==,T3u:>>:r_   c                "   [        XUS9u  pEnUS:X  a  [        R                  " XEXbS9u  pxXx4$ US:X  a  [        R                  " XTXbS9u  pXx4$ US:X  a  [        R                  " XEXbS9u  pxXx4$ US:X  a  [        R                  " XEU5      u  pxWW4$ )a  
Get join indexers for left and right.

Parameters
----------
left : ArrayLike
right : ArrayLike
sort : bool, default False
how : {'inner', 'outer', 'left', 'right'}, default 'inner'

Returns
-------
np.ndarray[np.intp]
    Indexer into left.
np.ndarray[np.intp]
    Indexer into right.
rk   rX   rY   rc   r   )r  libjoinleft_outer_join
inner_joinfull_outer_join)	rX   rY   rM   rR   r  r  countr  r  s	            r]   r  r    s    . ($?D
f},,TJ
 : 
,,TJ

 :	 
''EE
 : 
,,T?
:r_   c                v   SS jnU" U5      nUR                   nUR                  nUR                  n	U H  n
XR                  ;   a  U nUnOUnUnUR                  R                  U
5      nUR                   U   nUR                  U   nUc  UnO[        R
                  " XSS9nX~/-   nUU/-   nX/-   n	M     XxU	4$ )a  
*this is an internal non-public method*

Returns the levels, labels and names of a multi-index to multi-index join.
Depending on the type of join, this method restores the appropriate
dropped levels of the joined multi-index.
The method relies on lindexer, rindexer which hold the index positions of
left and right, where a join was feasible

Parameters
----------
left : MultiIndex
    left index
right : MultiIndex
    right index
dropped_level_names : str array
    list of non-common level names
join_index : Index
    the index of the join between the
    common levels of left and right
lindexer : np.ndarray[np.intp]
    left indexer
rindexer : np.ndarray[np.intp]
    right indexer

Returns
-------
levels : list of Index
    levels of combined multiindexes
labels : np.ndarray[np.intp]
    labels of combined multiindexes
names : List[Hashable]
    names of combined multiindex levels

c                    [        U [        5      (       a  U $ [        R                  " U R                  /U R                  /S9$ )N)r  )rx   r5   r  r/  r  )r   s    r]   _convert_to_multiindex@restore_dropped_levels_multijoin.<locals>._convert_to_multiindex9  s3    eZ((L))5==/%**NNr_   r#  r&  )r   r4   r   r5   )rg  rh  r  r   r0  r1  )rX   rY   dropped_level_namesr   lindexerrindexerr  join_levels
join_codesr   dropped_level_nameidxr]  name_idxrestore_levelsrh  restore_codess                    r]    restore_dropped_levels_multijoinr    s    XO (
3J##K!!J!!J 2+CGCG 99??#56H- 		(#?!M!MM%RHM "$44=/1
"66
/ 22 J..r_   c                  n    \ rS rSrSr        S                     SS jjrS	S
S jjrSrg)r   if  ordered_mergeNc                J    Xl         [        R                  U UUUUUUUU
USS9  g )NT)rH   rI   rK   rL   rJ   rR   rN   rM   )r   rV   r   )r   rX   rY   rH   rI   rJ   rK   rL   rN   r   rR   s              r]   r   _OrderedMerge.__init__i  s>     '  !# 	! 	
r_   c                <   U R                  5       u  p#nU R                  S:X  a9  Uc  S nO[        R                  " U5      nUc  S nO4[        R                  " U5      nOU R                  c  UnUnO[	        S5      eU R                  X%XaS9nU R                  XsU5        U$ )Nffillz#fill_method must be 'ffill' or NonerS   )r   r   r  ffill_indexerr   r   r   )r   rQ   r   r   r   left_join_indexerright_join_indexerr   s           r]   rW   _OrderedMerge.get_result  s    262E2E2G/
-
 w&#$(!$+$9$9,$G!$%)"%,%:%:=%I"% ,!.BCC))+= * 
 	!!&Fr_   )r   )NNNFFr  Nr   )rX   r  rY   r  rH   r   rI   r   rJ   r   rK   r   rL   r   rN   r   r   r   rR   r   r   r  r  r  )r  r  r  r  r   r   rW   r  rd   r_   r]   r   r   f  s    !K !%%)&* !)"&)0
 
 "
 	

 #
 $
 
 
 
  
 '
 

8 r_   r   c                0    SU  S3n[        [        US 5      $ )N
asof_join_
_on_X_by_Y)getattrr  )r   r  s     r]   _asof_by_functionr    s    	{*-D7D$''r_   c                     ^  \ rS rSrSr             S
                       SS jjrU 4S jr      SS jrSS jr      SS jr	SS jr
S	rU =r$ )r   i  
asof_mergec                >   Xl         Xl        Xl        Xl        Xl        Xl        U R
                  S;  a  [        SU R
                   35      e[        U R                  5      (       d  SU R                   3n[        U5      e[        R                  U UUUUUUUUUS S9  g )N)backwardforwardnearestzdirection invalid: z,allow_exact_matches must be boolean, passed )rH   rI   rJ   rK   rL   rR   rN   r   )
r   r   r   r   r   r   r   r!   r   r   )r   rX   rY   rH   rI   rJ   rK   rL   r   r   r   rN   rR   r   r   r   r   s                    r]   r   _AsOfMerge.__init__  s    $  "#6 " >>!CC24>>2BCDD t//002235  S/!!# 	 	
r_   c                d  > [         TU ]  X5      u  p[        U5      S:w  a  U R                  (       d  [	        S5      e[        U5      S:w  a  U R
                  (       d  [	        S5      eU R                  (       a4  [        U R                  R                  [        5      (       a  [	        S5      eU R
                  (       a4  [        U R                  R                  [        5      (       a  [	        S5      eU R                  b=  U R                  c  U R                  b  [	        S5      eU R                  =U l        U l        U R                  c  U R                  b  [	        S5      eU R                  b  U R                  c  [	        S5      eU R                  (       d  US	   n[        U[        5      (       a  UR                  nOX0R                  R                   ;   a%  U R                  R#                  U5      R                  O$U R                  R                  R%                  U5      nO U R                  R                  R                  nU R
                  (       d  US	   n[        U[        5      (       a  UR                  nOXPR                  R                   ;   a%  U R                  R#                  U5      R                  O$U R                  R                  R%                  U5      nO U R                  R                  R                  n['        U5      (       d0  ['        U5      (       d   [)        U5      (       d  [)        U5      (       a$  [	        S
[+        U5       S[+        U5       S35      eU R                  b  [-        U R                  5      (       d  U R                  /U l        [-        U R                  5      (       d  U R                  /U l        [        U R                  5      [        U R                  5      :w  a  [	        S5      eU R                  [/        U5      -   nU R                  [/        U5      -   nX4$ )Nrb   zcan only asof on a key for leftz can only asof on a key for rightzleft can only have one indexzright can only have one indexz(Can only pass by OR left_by and right_byzmissing left_byzmissing right_byr   zIncompatible merge dtype, rt  z$, both sides must have numeric dtypez,left_by and right_by must be the same length)superr   r   rK   r   rL   rx   rX   r   r5   rY   r   r   r   r   r*  ro   rf  r6  r)   r*   r  r&   ry   )r   rI   rJ   	left_on_0lo_dtype
right_on_0ro_dtype	__class__s          r]   r   "_AsOfMerge._validate_left_right_on  s#   !G;GN w<1T__>??x=Ad&6&6?@@??z$))//:FF;<<
4::+;+;Z H H<== 77||'4==+D !KLL+/772DL4=<<DMM$=.//<<#(=/00 
I)V,,$?? !II$5$55 II88CII99)D  yy,,H!!J*f--%++ "ZZ%7%77 JJ99*EKK)):::F  zz''--H H%%x((x((x((,T(^,<E>""FH  <<#-- $~..!%4<< C$66 !OPPllT']2G}}tH~5H  r_   c                N   SS jn[        [        X5      5       H  u  nu  pVU" XVU5        M     U R                  (       a!  U R                  R                  R
                  nOUS   nU R                  (       a!  U R                  R                  R
                  nOUS   nU" XxS5        g )Nc                   U R                   UR                   :w  a  [        U R                   [        5      (       aR  [        UR                   [        5      (       a3  SU S[        U R                   5       S[        UR                   5       S3nO2SU S[        U R                   5       S[        UR                   5       S3n[	        U5      eg )Nzincompatible merge keys [z] rt  z), both sides category, but not equal onesz, must be the same type)r*  rx   r,   r  r   )rX   rY   r  r   s       r]   _check_dtype_matchE_AsOfMerge._maybe_require_matching_dtypes.<locals>._check_dtype_match2  s    zzU[[(djj*:;;
KK!1A A 4A3bdjj9I8J%,--VX  4A3bdjj9I8J%,--DF  !o%+ )r_   r#  r   )rX   r   rY   r   r  int)r,  r  rK   rX   r   r/  rL   rY   )	r   r   r   r  r  rm  rn  ltrts	            r]   r   )_AsOfMerge._maybe_require_matching_dtypes-  s    
	&2 %S%IJKAxrq) K ??((B#B!!))B $B21%r_   c                   U R                   Gb  U R                  (       a!  U R                  R                  R                  nOUS   nSU R                    S[        UR                  5       3n[        UR                  5      (       d/  [        U[        5      (       as  UR                  R                  S;   aY  [        U R                   [        R                  5      (       d  [        U5      eU R                   [        S5      :  a  [        S5      eg [        UR                  5      (       aA  [!        U R                   5      (       d  [        U5      eU R                   S:  a  [        S5      eg [#        UR                  5      (       aA  [%        U R                   5      (       d  [        U5      eU R                   S:  a  [        S5      eg [        S5      eg )Nr#  zincompatible tolerance z, must be compat with type mMr   ztolerance must be positivez'key must be integer, timestamp or float)r   rK   rX   r   r/  r  r*  r+   rx   r7   r3  datetime	timedeltar   r   r%   r$   r#   r'   )r   r   r  r   s       r]   r   _AsOfMerge._validate_toleranceZ  sm   >>%YY__,,#B' *$..)9 :!"((^,. 
 #288,,22338M!$..(2D2DEE$S/)>>IaL0$%ABB 1 ""((++!$..11$S/)>>A%$%ABB &  )) 00$S/)>>A%$%ABB & !!JKKC &r_   c                   [        U5      R                  (       d;  [        U5      R                  5       (       a  [	        SU S35      e[	        U S35      e[        U[        5      (       a  UR                  5       n[        UR                  5      (       a  UR                  S5      nU$ [        U[        5      (       a  UR                  nU$ [        U[        5      (       a  UR                  5       nU$ )Nz"Merge keys contain null values on z sidez keys must be sortedi8)r4   r  r0   r.  r   rx   r7   _maybe_convert_datelike_arrayr+   r*  viewr8   _datar9   to_numpy)r   valuessides      r]   _convert_values_for_libjoin&_AsOfMerge._convert_values_for_libjoin  s     V}44F|!! #EdV5!QRRv%9:;;f12299;Fv||,,[[&F  00\\F  //__&F
 r_   c           	     h   U R                   (       a   U R                  R                  R                  OU R                  S   nU R
                  (       a   U R                  R                  R                  OU R                  S   nUR                  UR                  :X  d   eU R                  nUb  [        UR                  5      (       d/  [        U[        5      (       a  UR                  R                  S;   a  [        U5      nUR                  R                  S;   a\  [        U[        5      (       a!  UR                  R                  R                   nO[#        U5      R                   nUR%                  U5      nUR&                  nU R)                  US5      nU R)                  US5      nU R*                  GbI  U R                   (       a*  U R
                  (       a  U R                  nU R                  nOU R                  SS nU R                  SS n[-        [/        U5      5       Vs/ s H  n[1        XW   Xg   SS9PM     nn[/        U5      S	:X  a  US   S   n	US   S	   n
O]U Vs/ s H  n[2        R4                  " USS
 5      PM     nn[7        S U 5       5      n[9        XSSS9n[/        US   5      nUSU n	XS n
[;        U	5      n	[;        U
5      n
[=        U R>                  5      nU" UUU	U
U R@                  U5      $ [=        U R>                  5      nU" UUSSU R@                  US5      $ s  snf s  snf )rK  r#  Nr  rX   rY   r   Frk   rb   r  c              3  *   #    U  H	  oS    v   M     g7f)r  Nrd   )rp   r  s     r]   rr   0_AsOfMerge._get_join_indexers.<locals>.<genexpr>  s     3FqdFs   )r  rM   xnull)!rK   rX   r   r/  r   rL   rY   r   r*  r   r+   rx   r7   r3  r   pyarrow_dtypeunitr;   as_unit_valuer!  r   r   r   r  r[  concatenaterz   r?   r   r  r   r   )r   left_valuesright_valuesr   r(  r   r   rW  r  left_by_valuesright_by_valuesr  arrsr  group_indexleft_lenfuncs                    r]   rM  _AsOfMerge._get_join_indexers  s   
 (,DIIOO##D<O<OPR<S 	 )-(8(8DJJ$$d>R>RSU>V 	
   L$6$6666NN	  #;#4#455;(;<<%%**d2%i0	 $$))T1 "+/BCC*00>>CC=kJOO ) 1 1$ 7I%,,	 66{FK77gN <<#4#3#3!%!4!4"&"6"6!%!4!4Qr!:"&"6"6q"< s>23 4A  "%#&
 4   >"a'!'1"()A,7=>v!q!u-v>3F33-E ~a01!,Yh!7"-i"8).9N*?;O %T^^4D((  %T^^4D(( M ?s   #L*"#L/)r   r   r   r   r   r   )NNNFFNNNr  r   NTr   )rX   r  rY   r  rH   r   rI   r   rJ   r   rK   r   rL   r   rN   r   rR   zLiteral['asof']r   r   r   r   r   r  r  r  )r  r   r   r   r   
np.ndarrayr   1tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]])r  r  r  r  r   r   r   r   r   r!  rM  r  __classcell__)r
  s   @r]   r   r     s   K !%%)&* !)%$(#!1
 1
 "1
 	1

 #1
 $1
 1
 1
 1
 1
 "1
  !1
" 
#1
fN!`+&-+&@O+&	+&Z#LJ"*-	4` `r_   r   c                X  ^ ^^ UU U4S j[        TR                  5       5       n[        U6 nS U 5       u  pVnT(       a/  [        [	        [
        R                  UTR                  5      5      nO"S n[        [	        UTR                  5      5      n[        T 5       Hq  u  pTR                  U	   S:H  nUR                  5       (       d  M.  XU	   Xy   S-
  :H     nUR                  S:X  d  US   US   :w  d  Xy==   S-  ss'   Xy   S-
  XY   U'   Ms     [        Xe[        U5      T5      u  pX4$ )Nc              3  n   >#    U  H*  n[        TR                  U   R                  TU   TS 9v   M,     g7fr  )r  rg  r/  )rp   rW  r   	join_keysrM   s     r]   rr   *_get_multiindex_indexer.<locals>.<genexpr> 	  s3      %A 	Q//1DI%s   25c              3  8   #    U  H  n[        U5      v   M     g 7frm   r  r!  s     r]   rr   r<  	  r  r  c                $    U R                  SSSS9$ )Nr  FTsubokrQ   )r  )as    r]   r   )_get_multiindex_indexer.<locals>.<lambda>		  s    188DD8Ar_   r#  rb   r   )r   r   r  ry   mapr[  r   rh  r,  r.  sizer  rz   )r;  r   rM   r  r  rcodeslcodesr  i8copyr  join_keyr^  rA  r  r  s   ```            r]   _get_multiindex_indexerrI    s	   u}}%F &\F5f5FEc"''65;;78Ac&%++./ !+{{1~#88:: ehl23Avv{!A$!A$,A#hlFIdO ,  edCJD:r_   c                     [         R                  " / [         R                  S9[         R                  " / [         R                  S94$ )zReturn empty join indexers.r*  )r[  arrayintprd   r_   r]   r  r  	  s2     	277#
277# r_   c                    [         R                  " U [         R                  S9n[         R                  " U S[         R                  S9nU(       a  X24$ X#4$ )a  
Return join indexers where all of one side is selected without sorting
and none of the other side is selected.

Parameters
----------
n : int
    Length of indexers to create.
left_missing : bool
    If True, the left indexer will contain only -1's.
    If False, the right indexer will contain only -1's.

Returns
-------
np.ndarray[np.intp]
    Left indexer
np.ndarray[np.intp]
    Right indexer
rK  r#  )r  r'  r*  )r[  arangerM  full)rW  left_missingr  idx_missings       r]   r  r  %	  sC    , ))ARWW
%C''b@Kr_   c                "   [        U[        5      (       a  [        X!US9u  pEOUS   nUR                  n[	        XEUS9u  pgn[
        R                  " XgXS9u  pU(       d  [        U 5      [        U	5      :w  a  U R                  U	5      nXU
4$ U S U
4$ )Nrk   r   )	rx   r5   rI  r/  r  r  r  r   r   )rU  rV  r;  rM   r  r  r  r  r  r   r   r   s               r]   rS  rS  B	  s     (J'',YtL
d
 | !0$!GH")"9"9U#L s7|s<00\\,/
66 D-''r_   c                   [        U R                  [        5      (       a  [        UR                  [        5      (       dL  [        R                  " U R                  S5      (       aq  [        R                  " UR                  S5      (       aK  [        SU 5      R                  U5      u  p[        SU 5      R                  n [        SU5      R                  nGO[        U R                  [        5      (       a  [        UR                  [        5      (       a  U R                  UR                  :X  ak  [        U [        5      (       d   e[        U[        5      (       d   eU R                  U5      n[        U R                  5      n [        UR                  5      nGO[        U [        5      (       Ga  U R                  UR                  :X  Ga  [        U R                  [        5      (       a  [        U R                  5      (       d;  [        U R                  [         5      (       Ga  U R                  R"                  S;   Ga  SSKnSSKJn  [+        U 5      nU R,                  n UR,                  nUR/                  U R0                  UR0                  -   5      R3                  5       R5                  5       nUR7                  UR8                  [;        U5         S5      R=                  5       R?                  [@        RB                  SS9UR7                  UR8                  [;        US5         S5      R=                  5       R?                  [@        RB                  SS9[+        URD                  5      pnU(       a'  URD                  R=                  SS	9n
[G        XU5      u  pxURH                  S:  ak  US:H  nURK                  5       nUS:H  nURK                  5       nU(       a  [@        RL                  " X{U	5        U(       a  [@        RL                  " XU	5        U	S
-  n	XxU	4$ [        U [N        5      (       d  [        U R                  [        5      (       aE  [Q        U R                  RR                  5      (       dE  [        U R                  5      (       a  U(       a$  U RU                  5       u  pURU                  5       u  p[W        U R                  5      (       a`  U R                  UR                  :X  aF  [@        RX                  " U [@        RZ                  S9n [@        RX                  " U[@        RZ                  S9n[]        X5      u  npU" [_        [+        U 5      [+        U5      5      5      n[        U [N        5      (       a`  [        U[N        5      (       d   eURa                  U Rb                  U Rd                  S9nURa                  URb                  URd                  S9nO[        U [f        5      (       a  [        U[f        5      (       d   eURa                  U R=                  S
U R                  RR                  S9U Ri                  5       S9nURa                  UR=                  S
U R                  RR                  S9URi                  5       S9nO"URa                  U 5      nURa                  U5      nUR                  [@        R                  " [@        RB                  5      :X  d   UR                  5       eUR                  [@        R                  " [@        RB                  5      :X  d   UR                  5       eURk                  5       n	U(       a(  URl                  Ro                  5       n
[G        XU5      u  pxUS:H  nURK                  5       nUS:H  nURK                  5       nU(       d  U(       aA  U(       a  [@        RL                  " X{U	5        U(       a  [@        RL                  " XU	5        U	S
-  n	XxU	4$ )aW  
Encode left and right keys as enumerated types.

This is used to get the join indexers to be used when merging DataFrames.

Parameters
----------
lk : ndarray, ExtensionArray
    Left key.
rk : ndarray, ExtensionArray
    Right key.
sort : bool, defaults to True
    If True, the encoding is done such that the unique elements in the
    keys are sorted.

Returns
-------
np.ndarray[np.intp]
    Left (resp. right if called with `key='right'`) labels, as enumerated type.
np.ndarray[np.intp]
    Right (resp. left if called with `key='right'`) labels, as enumerated type.
int
    Number of unique elements in union of left and right labels.

See Also
--------
merge : Merge DataFrame or named Series objects
    with a database-style join.
algorithms.factorize : Encode the object as an enumerated type
    or categorical variable.

Examples
--------
>>> lk = np.array(["a", "c", "b"])
>>> rk = np.array(["a", "c"])

Here, the unique values are `'a', 'b', 'c'`. With the default
`sort=True`, the encoding will be `{0: 'a', 1: 'b', 2: 'c'}`:

>>> pd.core.reshape.merge._factorize_keys(lk, rk)
(array([0, 2, 1]), array([0, 2]), 3)

With the `sort=False`, the encoding will correspond to the order
in which the unique elements first appear: `{0: 'a', 1: 'c', 2: 'b'}`:

>>> pd.core.reshape.merge._factorize_keys(lk, rk, sort=False)
(array([0, 1, 2]), array([0, 1]), 3)
r(  rC   )pyarrowpyarrow_numpyr   Nr#  FrS   )zero_copy_onlyrb   rK  )r^  )na_valuer*  )8rx   r*  r-   r   is_np_dtyper	   _ensure_matching_resos_ndarrayr,   r3   _encode_with_my_categoriesr   rh  r9   r2   r*   r:   storagerU  pyarrow.computecomputer   	_pa_arraychunked_arraychunkscombine_chunksdictionary_encode	fill_nullr   slicer  r  r[  rM  
dictionary_sort_labels
null_countr.  putmaskr8   r(   numpy_dtype_values_for_factorizer+   asarrayint64#_convert_arrays_and_get_rizer_klassmax	factorizer  _maskr7   r0   	get_countuniquesto_array)rm  rn  rM   papclen_lkdcr  r  r  rt  lmasklanyrmaskranyr   klassrizers                     r]   r  r  ^	  s   l 	288_--*RXX2W2W
//"((C
(
(S__RXXs-K-K or*AA"E/2&///2&// 	288-..rxx!122HH "k****"k**** **2."((#"((#	B	'	'BHH,@rxx,,1J1Jrxx--  $@@ (WFBB  RYY!67!""$  RZZf6;e,RZZfd(;<bAe,BMM" D --000F)'>
}}q 
yy{
yy{JJtE2JJtE2
u$$"o..rxx,, !5!566"288,, ,,.EB ,,.EB288$$RXX)= ZZ"((+ZZ"((+7?ME2#c"gs2w'(E"o&&"o....rxxbhh7rxxbhh7	B+	,	,"12222 KK"((*>*>K?bggi  
 KK"((*>*>K?bggi  
 r"r"::"''**6DJJ6*::"''**6DJJ6*OOE--((*!'6
 BJE99;DBJE99;DtJJtE*JJtE*
ur_   c                   [        U R                  5      (       Ga  U R                  UR                  :w  a  [        U R                  UR                  /5      n[        U[        5      (       a}  UR                  5       n[        U [        5      (       d  UR                  XSS9n OU R                  USS9n [        U[        5      (       d  UR                  XSS9nO1UR                  USS9nO U R                  USS9n UR                  USS9n[        U [        5      (       a  [        U R                  R                     nO[        U R                  [        5      (       a(  [        U R                  R                  R                     nOD[        U R                  R                     nO&[        R                  n[!        U 5      n [!        U5      nX@U4$ )NFru  rS   )r(   r*  r   rx   r   r  r9   r  r  r8   _factorizersr   r2   rk  libhashtableObjectFactorizerr    )rm  rn  r*  clsr~  s        r]   ro  ro  
  sj    !!88rxx$bhh%9:E%00002!"n55++B%+HB5u5B!"n55++B%+HB5u5BYYu5Y1YYu5Y1b/** !/E*-- !5!5!:!:;E /E --22b=r_   c                    [        U5      n[        R                  " X/5      n[        R                  " XSS9u  pVUS U XcS  pXx4$ )NT)use_na_sentinel)r   r[  r+  r0  	safe_sort)	rt  rX   rY   llengthr  r   
new_labelsnew_left	new_rights	            r]   rh  rh  A
  sK     $iG^^TM*FOOGTJMA$Xg.
80Dir_   c                "  ^ [        U4S j[        [        T5      SS5       5       5      n[        R                  " TSU SS9nXPS   R                  SSSS9-  nXQS   R                  SSSS9-  n[        SU5       H<  n[        R                  " S	S
9   UTU   -  nS S S 5        X`U   U-  -  nXqU   U-  -  nM>     U[        T5      :X  a  Xg4$ [        XgUS9u  pgn	U/XS  -   n U/XS  -   nU	4TUS  -   m[        XTU5      $ ! , (       d  f       Nk= f)Nc              3  R   >#    U  H  n[        TS U 5      (       a  M  Uv   M     g 7frm   )r@   )rp   rp  r  s     r]   rr   !_get_join_keys.<locals>.<genexpr>T
  s(      +C)%+6 	+s   '	'r   r#  rb   r  rK  Fr?  rv  )dividerk   )	nextr   r   r[  prodr  r  r  r  )
r  r  r  rM   nlevstrider  r  r  r  s
     `       r]   r  r  M
  s;     UQ+ D WWU1T]$/FGNN4u5NAADGNN4u5NAAD1d^[[)uQxF *Q&  Q&  	  s5zz (>D6DKD6DKDHuTU|#E$eT22 *)s   	D  
D	c                `    [        U [        5      (       a  [        U[        5      (       d  gX:H  $ )NT)rx   r   )r;  r<  s     r]   r-  r-  r
  s&    eS!!E3)?)?>r_   c                >    U S L=(       a    [         R                  " U 6 $ rm   )r   any_not_none)r   s    r]   re  re  x
  s    D=1S--q11r_   c                    [        U [        5      (       a  U $ [        U [        5      (       a(  U R                  c  [	        S5      eU R                  5       $ [        S[        U 5       S35      e)Nz$Cannot merge a Series without a namez.Can only merge Series or DataFrame objects, a z was passed)rx   r.   r/   r  r   to_frame	TypeErrorr   )objs    r]   rT   rT   |
  s`    #|$$
	C	#	#88CDD||~<T#YK{S
 	
r_   c                  ^ [        USS9(       a  [        U[        5      (       a  [        S[	        U5       S35      eU R                  U5      m[        T5      S:X  a  X4$ Uu  p4U(       d  U(       d  [        ST 35      eSU4S jjn[        XSS9n[        XTS9nU R                  U5      nUR                  U5      n	/ n
UR                  (       d2  XR                  5       U R                  5       ) -     R                  5       n
U	R                  (       dA  U
R                  XR                  5       UR                  5       ) -     R                  5       5        U
(       a  [        S	[        U
5       S
35      eX4$ )z
Suffixes type validation.

If two indices overlap, add suffixes to overlapping entries.

If corresponding suffix is empty, the entry is simply converted to string.

F)
allow_setszPassing 'suffixes' as a z:, is not supported. Provide 'suffixes' as a tuple instead.r   z)columns overlap but no suffix specified: c                &   > U T;   a	  Ub  U  U 3$ U $ )z
Rename the left and right indices.

If there is overlap, and suffix is not None, add
suffix, otherwise, leave it as-is.

Parameters
----------
x : original column name
suffix : str or None

Returns
-------
x : renamed column name
rd   )r   suffix	to_renames     r]   renamer+_items_overlap_with_suffix.<locals>.renamer
  s$      	>f0S>!r_   )r  z1Passing 'suffixes' which cause duplicate columns z is not allowed.)r  r   )r&   rx   dictr  r   r  r   r   r   _transform_indexr  
duplicatedr   extendr   r   )rX   rY   rN   lsuffixrsuffixr  lrenamerrrenamerr   r   dupsr  s              @r]   r   r   
  sd    U3z(D7Q7Q&tH~&6 75 5
 	

 !!%(I
9~{G7DYKPQQ( w/Hw/H##H-G$$X.GD **,$//2C1CDELLNG//1u7G7G7I6IJKRRTU?D	{ K 
 	

 r_   )rc   NNNFFFr  NFN)rX   r  rY   r  rR   r   rH   r  rI   r  rJ   r  rK   r   rL   r   rM   r   rN   r   rQ   r  rO   r   rP   r   r   rA   )
NNNFFFr  NFN)rX   rA   rY   rA   rH   r  rI   r  rJ   r  rK   r   rL   r   rM   r   rN   r   rQ   r  rO   r   rP   r   r   rA   )rX   r  rY   r  )NNNNNNr  r   )rX   r  rY   r  rH   r   rI   r   rJ   r   r   r   rN   r   rR   r   r   rA   )NNNFFNNNr  NTr   )rX   r  rY   r  rH   r   rI   r   rJ   r   rK   r   rL   r   rN   r   r   zint | Timedelta | Noner   r   r   r   r   rA   )Frc   )
ri  r   rj  r   rM   r   rR   r   r   r  )
rX   r   rY   r   rM   r   rR   r   r   r7  )rX   r5   rY   r5   r   r4   r  npt.NDArray[np.intp]r  r  r   z)tuple[FrozenList, FrozenList, FrozenList])r   r   )r;  r   r   r5   rM   r   r   r7  r6  )rW  r  rQ  r   r   r7  )F)
rU  r4   rV  r4   r;  r   rM   r   r   z?tuple[Index, npt.NDArray[np.intp] | None, npt.NDArray[np.intp]]r  )rm  r   rn  r   rM   r   r   z6tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int])rm  r   rn  r   r   z:tuple[type[libhashtable.Factorizer], ArrayLike, ArrayLike])rt  r5  rX   r  rY   r  r   r7  )
r  %list[npt.NDArray[np.int64 | np.intp]]r  r  r  r   rM   r   r   z3tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]])r   r   )r  r  r   rA   )rX   r4   rY   r4   rN   r   r   ztuple[Index, Index])r  
__future__r   collections.abcr   r   r  	functoolsr   typingr   r   r	   r
   re   r  numpyr[  pandas._libsr   r   r  r   r  r   pandas._libs.libr   pandas._typingr   r   r   r   r   r   r   r   pandas.errorsr   pandas.util._decoratorsr   r   r   pandas.util._exceptionsr   pandas.core.dtypes.baser   pandas.core.dtypes.castr   pandas.core.dtypes.commonr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   pandas.core.dtypes.dtypesr,   r-   pandas.core.dtypes.genericr.   r/   pandas.core.dtypes.missingr0   r1   r   r2   r3   r4   r5   r6   pandas.core.algorithmscore
algorithmsr0  pandas.core.arraysr7   r8   r9   pandas.core.arrays.string_r:   pandas.core.commoncommonr   pandas.core.constructionr;   r<   pandas.core.framer=   pandas.core.indexes.apir>   pandas.core.sortingr?   r@   rA   pandas.corerB   rC   pandas.core.indexes.frozenrD   rn  Int64Factorizerlonglongint32Int32Factorizerint16Int16Factorizerr   Int8Factorizeruint64UInt64Factorizeruint32UInt32Factorizeruint16UInt16Factorizeruint8UInt8Factorizerbool_float64Float64Factorizerfloat32Float32Factorizer	complex64Complex64Factorizer
complex128Complex128Factorizerobject_r  r  intcndarrayr   r^   rU   r   r   r   rV   rL  r  r  r   r  r   rI  r  r  rS  r  ro  rh  r  r-  re  rT   r   rd   r_   r]   <module>r     s   #        .	 	 	 % 
 5 2 4   
  ' & 
 3     ) 1
  #05 HHl**KK--HHl**HHl**GG\((II|,,II|,,II|,,HHl**HHl**JJ..JJ..LL,22MM<44JJ--& 77"(((88L
**neY	7 23	*a  +/0415%!/(
/(/( 
/( 	)	/(
 ./( //( /( /( /( /( /( /( /( /( ! 4/(j ,00415%!4
44 	)4 .	4
 /4 4 4 4 4 4 4 4 4n6 6);6x !!%"&"%J
JJ 	J 	J
  J J J 
J J` !!%"&%(, $L
LL 	L 	L
  L L L L &L L L LbP Pl 	KKK K 
	K
 EKb 	 
     
	 
 7 FV/
V/V/ 	V/
 #V/ #V/ /V/r9O 9x(
R Rj
'19=6B
6< OT((#(0?(GK(D(: 04{{ {(,{;{|"" "?"J		3	<P	6	"3
/"3
/"3 "3 	"3
 9"3J2

A
AA)1AAr_   