
    h!                    n   d dl mZ d dlmZmZmZ d dlZd dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZ d dlmZ erd d	lmZ d d
lmZ e	 ddd	 	 	 	 	 	 	 	 	 dd       Zedd	 	 	 	 	 	 	 	 	 dd       Ze	 dddd	 	 	 	 	 	 	 	 	 dd       Zeddd	 	 	 	 	 	 	 	 	 dd       Z	 dedd	 	 	 	 	 	 	 	 	 ddZy)    )annotations)TYPE_CHECKINGLiteraloverloadN)libmissing)find_stack_levelmaybe_box_native)BaseMaskedDtypeExtensionDtype)common)MutableMappingT)	DataFrame.)indexc                    y N dforientintor   s       @D:\jyotish\venv\Lib\site-packages\pandas/core/methods/to_dict.pyto_dictr                c                    y r   r   r   s       r   r   r   +   r   r   )r   r   c                    y r   r   r   s       r   r   r   6   r   r   c                    y r   r   r   s       r   r   r   A   r   r   Tc               2
     j                   j                  s$t        j                  dt        t                      t        j                        }|j                         }|s|dvrt        d      |dk(  r |d  j                         D              S t         j                  j                        D cg c]3  \  }}|t        j                  t               k(  st#        |t$              r|5 }}}t         j                  j                        D cg c]5  \  }}t#        |t&              st(        j*                  nt,        j.                  7 c}}t1        |      t1         j                        k(  }|dk(  r |fd j                         D              S |d	k(  r4t3        |       |fd
t         j                               D              S |dk(  rZ j5                  ||      }	 ||rd j6                  j9                         ffndd j                   j9                         fd|	ffz         S |dk(  rډ j5                  ||      }	 ||rd j6                  j9                         ffndd j                   j9                         fd j;                  dd      D 
cg c]  }
t=        t?        t@        |
             c}
ffz   |r"dt=         j6                  jB                        ffndz   dt=         j                   jB                        ffz         S |dk(  r j                   j9                         |rGfd j;                  dd      D        }|D cg c]  } |d |j                         D              ! c}S  j;                  dd      D 
cg c]  }
 |tE        |
             }	}
|rUt3        |      t         j                         D ch c]  \  }}|v r| }}}|	D ]  }|D ]  }tA        ||         ||<     |	S |dk(  r܉ j6                  j                  st        d       j                   j9                         |r! | fd j;                  d      D              S |r[t3        |      tG        t1         j                               D cg c]  }|v  c} |fd j;                  d      D              S  | fd j;                  d      D              S t        d| d      c c}}w c c}}w c c}
w c c}w c c}
w c c}}w c c}w ) a  
    Convert the DataFrame to a dictionary.

    The type of the key-value pairs can be customized with the parameters
    (see below).

    Parameters
    ----------
    orient : str {'dict', 'list', 'series', 'split', 'tight', 'records', 'index'}
        Determines the type of the values of the dictionary.

        - 'dict' (default) : dict like {column -> {index -> value}}
        - 'list' : dict like {column -> [values]}
        - 'series' : dict like {column -> Series(values)}
        - 'split' : dict like
          {'index' -> [index], 'columns' -> [columns], 'data' -> [values]}
        - 'tight' : dict like
          {'index' -> [index], 'columns' -> [columns], 'data' -> [values],
          'index_names' -> [index.names], 'column_names' -> [column.names]}
        - 'records' : list like
          [{column -> value}, ... , {column -> value}]
        - 'index' : dict like {index -> {column -> value}}

        .. versionadded:: 1.4.0
            'tight' as an allowed value for the ``orient`` argument

    into : class, default dict
        The collections.abc.MutableMapping subclass used for all Mappings
        in the return value.  Can be the actual class or an empty
        instance of the mapping type you want.  If you want a
        collections.defaultdict, you must pass it initialized.

    index : bool, default True
        Whether to include the index item (and index_names item if `orient`
        is 'tight') in the returned dictionary. Can only be ``False``
        when `orient` is 'split' or 'tight'.

        .. versionadded:: 2.0.0

    Returns
    -------
    dict, list or collections.abc.Mapping
        Return a collections.abc.MutableMapping object representing the
        DataFrame. The resulting transformation depends on the `orient` parameter.
    z?DataFrame columns are not unique, some columns will be omitted.)
stacklevel)splittightz?'index=False' is only valid when 'orient' is 'split' or 'tight'seriesc              3  *   K   | ]  \  }}||f  y wr   r   .0kvs      r   	<genexpr>zto_dict.<locals>.<genexpr>   s     4Aq!fs   dictc              3  L   K   | ]  \  }}||j                         f  yw))r   N)r   )r'   r(   r)   r   s      r   r*   zto_dict.<locals>.<genexpr>   s&     GJDAqq!)))./Js   !$listc              3     K   | ]c  \  }\  }}||v r,t        t        t        |j                  |                      n&t        t        t        |j                                     f e yw))na_valueN)r-   mapr   to_numpy)r'   ir(   r)   box_na_valuesobject_dtype_indices_as_sets       r   r*   zto_dict.<locals>.<genexpr>   sk      
 3	6Aq 33 S)1::}Q?O:+PQR#.

=>	 3s   A)A,r"   r   r   columnsdatar#   FN)r   nameindex_namescolumn_namesrecordsc              3  H   K   | ]  }t        t        |              y wr   )r+   zip)r'   rowr5   s     r   r*   zto_dict.<locals>.<genexpr>   s"      3XCS#&'3Xs   "c              3  <   K   | ]  \  }}|t        |      f  y wr   r
   r&   s      r   r*   zto_dict.<locals>.<genexpr>   s      HKDAq+A./Ks   z2DataFrame index must be unique for orient='index'.c              3     K   | ]9  }|d    t        t        j                  t        t        |dd                   f ; ywr      N)r+   r<   r5   r0   r   r'   tr   s     r   r*   zto_dict.<locals>.<genexpr>   s@      1A 1tC

C0@!AB%,HIJK1s   ?A)r7   c           
   3     K   | ]>  }|d    t        |dd       D ci c]  \  }}|   |   rt        |      n| c}}f @ yc c}}w wr@   )	enumerater   )r'   rC   r2   r)   r5   is_object_dtype_by_indexs       r   r*   zto_dict.<locals>.<genexpr>   sy       2A aD
 %.ae$4	 %5DAq  
3A6 %5Q$7 %5	 2s   A A
Ac           
   3  l   K   | ]+  }|d    t        t        j                  |dd             f - ywr@   )r+   r<   r5   rB   s     r   r*   zto_dict.<locals>.<genexpr>  s5      >V1tC

AabE234>Vs   14zorient 'z' not understood)$r5   	is_uniquewarningswarnUserWarningr	   comstandardize_mappinglower
ValueErroritemsrE   dtypesvaluesnpdtypeobject
isinstancer   r   r   
no_default
libmissingNAlenset(_create_data_for_split_and_tight_to_dictr   tolist
itertuplesr-   r0   r   namesr<   range)r   r   r   r   into_cr2   	col_dtypebox_native_indicesare_all_object_dtype_colsr6   rC   rowsr=   colobject_dtype_colsr3   r5   rF   r4   s   ` `            @@@@r   r   r   N   s3   l ::M')	
 $$T*F
 \\^FV#55M
 	
 4444 &bii&6&677LAy((Jy.,Q 	
7   &bii&6&677LAy )OD*--W7M !$$6 73ryy> IGBHHJGGG	6	034F0G# 
 'rxxz2
 
 	
 
7	::%'9
 05w)*,2BJJ--/0
 	
 
7	::%'9
 05w)*,2BJJ--/0 "$U!F!FA S!1156!F	
 <ARXX^^ 457bJ RZZ%5%5 679:
 	
  
9	**##%$35==uSW=3XD UYTXSHCIIKHHTX 
 24UQU1V1VAs7A'1V   ".12D.E+ #,BJJ"7%"7377 "7 " %
  C0#3CH#=C  1   K	7	xx!!QRR**##%$ D1    *-.@*A':?BJJ:P(:PQ00:P($   D1    >@mmQUm>V  
 8F8+;<==k
Z 
%*(s*   ;8S3:S9 S?$TT	TT).)
r   r   r   <Literal['dict', 'list', 'series', 'split', 'tight', 'index']r   'type[MutableMappingT] | MutableMappingTr   boolreturnr   )
r   r   r   Literal['records']r   ri   r   rj   rk   zlist[MutableMappingT])
r   r   r   rh   r   
type[dict]r   rj   rk   r+   )
r   r   r   rl   r   rm   r   rj   rk   z
list[dict])r+   )
r   r   r   zGLiteral['dict', 'list', 'series', 'split', 'tight', 'records', 'index']r   ri   r   rj   rk   z'MutableMappingT | list[MutableMappingT])
__future__r   typingr   r   r   rI   numpyrS   pandas._libsr   r   rX   pandas.util._exceptionsr	   pandas.core.dtypes.castr   pandas.core.dtypes.dtypesr   r   pandas.corer   rL   pandas._typingr   pandasr   r   r+   r   r   r   <module>rx      s   " 
   5 4
 &.  
 LO
 H 2	
   
 
  2	
   
 
 LO H 	
  
 
 

  	
   
  		B> 59B>B>B> 2B> B> -B>r   