
     j                    B    d dl mZ d dlZd dlmZ d dlmZmZm	Z	 ddZ
dS )    )annotationsN)unique1d)CategoricalCategoricalDtyperecode_for_categoriescr   sortboolobservedreturn&tuple[Categorical, Categorical | None]c                $   |rt          | j                  }||dk             }|rt          j        |          }| j                            |          }t          | j        | j        |          }t          || j                  }t          j
        ||          | fS |r| dfS t          j        | j                                                  }t          | j        | j        dk                       }	|rt          j        |	          }	t          |          t          |	          k    r.t          j        ||	d          }
t          j        |	|
f          }n|	}t          | |                                 j                            |                    dfS )a=  
    Code the categories to ensure we can groupby for categoricals.

    If observed=True, we return a new Categorical with the observed
    categories only.

    If sort=False, return a copy of self, coded with categories as
    returned by .unique(), followed by any categories not appearing in
    the data. If sort=True, return self.

    This method is needed solely to ensure the categorical index of the
    GroupBy result has categories in the order of appearance in the data
    (GH-8868).

    Parameters
    ----------
    c : Categorical
    sort : bool
        The value of the sort parameter groupby was called with.
    observed : bool
        Account only for the observed values

    Returns
    -------
    Categorical
        If sort=False, the new categories are set to the order of
        appearance in codes (unless ordered=True, in which case the
        original order is preserved), followed by any unrepresented
        categories in the original order.
    Categorical or None
        If we are observed, return the original categorical, otherwise None
    )ordered)dtypeNT)assume_unique)r   codesnpr	   
categoriestaker   r   r   r   _simple_newarangenuniquelen	setdiff1dconcatenateunique)r   r	   r   unique_codes
take_codesr   r   r   	all_codesunique_notnan_codesmissing_codess              sC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\pandas/core/groupby/categorical.pyrecode_for_groupbyr$      s   H  >  ((!,""45
 	-,,J \&&z22
%agq|ZHH !QY???&uE:::A==  $w
 	!,..0011I"1717b=#9:: ; g&9::
9~~/000 )Y0CSWXXX^%8-$HII

(
q!((**/44Z@@AA4GG    )r   r   r	   r
   r   r
   r   r   )
__future__r   numpyr   pandas.core.algorithmsr   pandas.core.arrays.categoricalr   r   r   r$    r%   r#   <module>r+      s    " " " " " "     + + + + + +         JH JH JH JH JH JHr%   