| Server IP : 209.209.40.120 / Your IP : 216.73.217.112 Web Server : Microsoft-IIS/10.0 System : Windows NT NEWWWW 10.0 build 17763 (Windows Server 2019) i586 User : NEWWWW$ ( 0) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Python312/Lib/site-packages/pandas/core/groupby/__pycache__/ |
Upload File : |
�
- �g� � �P � d dl mZ d dlZd dlmZ d dlmZmZm Z dd�Z
y)� )�annotationsN)�unique1d)�Categorical�CategoricalDtype�recode_for_categoriesc � � |r�t | j � }||dk7 }|rt j |� }| j j |� }t
| j | j |� }t || j �� }t j ||�� | fS |r| dfS t j | j j � � }t | j | j dk7 � } |rt j | � } t |� t | � kD r0t j || d�� }
t j | |
f� }n| }t | | j! � j j |� � dfS )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�np�sort�
categories�taker r r
r �_simple_new�arange�nunique�len� setdiff1d�concatenate�unique)�cr �observed�unique_codes�
take_codesr r
r � all_codes�unique_notnan_codes�
missing_codess �AC:\Python312\Lib\site-packages\pandas/core/groupby/categorical.py�recode_for_groupbyr!
sP � �H � ����(��!�,�"�"4�5�
������,�J� �\�\�&�&�z�2�
�%�a�g�g�q�|�|�Z�H�� !��Q�Y�Y�?���&�&�u�E�:�A�=�=� ��$�w��
� � �!�,�,�.�.�0�1�I�"�1�7�7�1�7�7�b�=�#9�:��� �g�g�&9�:��
�9�~��/�0�0����Y�0C�SW�X�
��^�^�%8�-�$H�I�
�(�
��q�!�(�(�*�/�/�4�4�Z�@�A�4�G�G� )r r r �boolr r# �returnz&tuple[Categorical, Categorical | None])�
__future__r �numpyr �pandas.core.algorithmsr �pandas.core.arrays.categoricalr r r r! � r"