i dZddlmZddlmZmZddlZddlmZddl m Z m Z m Z ddl Z ddlZddlZddlmZmZmZmZmZmZddlZddlZddlmZddlZddlZdd lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'dd l(m)Z)m*Z+m,Z,m-Z-m.Z.ddl/Z/ddl0Z0dd l1m2Z2m3Z3dd l4m5Z5dd l6m7Z7ddl8m9Z9m:Z:m;Z;mZ>e?e.e,ze-zZ@e@AdejBdZCe%de2ZDerddlEmFZFddl1mGZGmHZHmIZImJZJmKZKmLZLddlMmNZNe jOGddZPe jOGdde#e!ZQd|dZRe'd}d"ZSe'd~d#ZSdd%ZSdd(ZTe' ddd,ZUe' ddd-ZU ddd0ZUdd4ZVdd6ZW ddd?ZXddAZYdBdBdBdBdCdDdEdFdGdH ZZe?eZ[Z\ddKZ]ddMZ^ddOZ_e'd)d)d)d)d)dPddXZ`e'd)d)d)d)d)d)dYdd\Z`e'd)d)d)d)d)d)dYdd^Z`ddd.d_dddYdd`Z`GdadbeeZaGdcddeaZbGdedfeaZcGdgdhZdGdidjZeddnZfddoZgddpZhejiddrZj dddwZkdd{ZldS)zCommon I/O API utilities) annotations)ABCabstractmethodN) defaultdict)HashableMappingSequence)BufferedIOBaseBytesIO RawIOBaseStringIO TextIOBase TextIOWrapper)Path) IO TYPE_CHECKINGAnyAnyStr DefaultDictGenericLiteralTypeVarcastoverload)urljoinurlparse uses_netloc uses_params uses_relative) BaseBuffer ReadCsvBuffer)import_optional_dependency)find_stack_level)is_bool is_file_like is_integer is_list_like) ABCMultiIndexz3^[A-Za-z][A-Za-z0-9+\-+.]*(::[A-Za-z0-9+\-+.]+)*:// BaseBufferT)bound) TracebackType)CompressionDictCompressionOptionsFilePath ReadBufferStorageOptions WriteBuffer) MultiIndexcJeZdZUdZded<ded<ded<ded<d Zd ed <d S) IOArgsz? Return value of io/common.py:_get_filepath_or_buffer. str | BaseBufferfilepath_or_bufferstrencodingmoder- compressionFbool should_closeN)__name__ __module__ __qualname____doc____annotations__r=BC:\PYTHON\GemmaReport\python\Lib\site-packages\pandas/io/common.pyr5r5[sY)(((MMM III    LrDr5czeZdZUdZded<ded<ejeZded<d Z d ed <ddZ ddZ ddZ dS) IOHandlesau Return value of io/common.py:get_handle Can be used as a context manager. This is used to easily close created buffers and to handle corner cases when TextIOWrapper is inserted. handle: The file handle to be used. created_handles: All file handles that are created by get_handle is_wrapped: Whether a TextIOWrapper needs to be detached. z IO[AnyStr]handler-r;)default_factoryzlist[IO[bytes] | IO[str]]created_handlesFr< is_wrappedreturnNonecF|jrmt|jtsJ|j|j|j|j|jD]}|g|_d|_dS)z Close all created buffers. Note: If a TextIOWrapper was inserted, it is flushed and detached to avoid closing the potentially user-created buffer. FN) rK isinstancerHrflushdetachrJremoveclose)selfrHs rErSzIOHandles.close}s ? 5dk=99 9 99 K      K    ' ' 4 4 4*  F LLNNNN!rDIOHandles[AnyStr]c|SNrCrTs rE __enter__zIOHandles.__enter__s rDexc_typetype[BaseException] | None exc_valueBaseException | None tracebackTracebackType | Nonec.|dSrW)rS)rTrZr\r^s rE__exit__zIOHandles.__exit__s rDNrLrM)rLrU)rZr[r\r]r^r_rLrM) r>r?r@rArB dataclassesfieldlistrJrKrSrYrarCrDrErGrGhs      1B1BSW1X1X1XOXXXXJ    "rDrGurlobjectrLr<cft|tsdSt|jtvS)z Check to see if a URL has a valid protocol. Parameters ---------- url : str or unicode Returns ------- isurl : bool If `url` has a valid protocol return True otherwise False. F)rOr8 parse_urlscheme _VALID_URLSrfs rEis_urlrms/ c3  u S>> K //rDr7r8cdSrWrCr7s rE _expand_userrps25#rDcdSrWrCros rErprpsBE#rDstr | BaseBufferTcnt|trtj|S|S)a] Return the argument with an initial component of ~ or ~user replaced by that user's home directory. Parameters ---------- filepath_or_buffer : object to be converted if possible Returns ------- expanded_filepath_or_buffer : an expanded filepath or the input if not expandable )rOr8ospath expanduserros rErprps4$c**6w!!"4555 rDheaderrMc|dSt|r,tt|}|dkrtddSt |drptt |}t tt|stdtd|DrtddSt|rtdtd) NrzUPassing negative integer to header is invalid. For no header, use header=None insteadF) allow_setsz*header must be integer or list of integersc3"K|] }|dkV dS)rNrC).0is rE z&validate_header_arg..s&%%q1u%%%%%%rDz8cannot specify multi-index header with negative integerszPassing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names) r&rint ValueErrorr'r allmapanyr$ TypeError)rws rEvalidate_header_argrs  ~&c6"" A::9  Fu---h''3z6**++ KIJJ J %%f%%% % % YWXX Xv  4   A B BBrD.r/convert_file_likecdSrWrCr7rs rEstringify_pathrs  #rDcdSrWrCrs rErrs #rDFFilePath | BaseBufferTc|s$t|rtt|St|tjr|}t|S)a Attempt to convert a path-like object to a string. Parameters ---------- filepath_or_buffer : object to be converted Returns ------- str_filepath_or_buffer : maybe a string version of the object Notes ----- Objects supporting the fspath protocol are coerced according to its __fspath__ method. Any other object is passed through unchanged, which includes bytes, strings, buffers, or anything else that's not even path-like. )r%rr*rOrtPathLike __fspath__rprs rErrse. 5.@!A!A5K!3444$bk22=/::<< * + ++rDargsrkwargsc.ddl}|jj|i|S)z` Lazy-import wrapper for stdlib urlopen, as that imports a big chunk of the stdlib. rN)urllib.requestrequesturlopen)rrurllibs rErrs*  !6> !4 26 2 22rDFilePath | BaseBufferct|tot|dr.d|vr*t jdt td}t||}d|vr5|dvr1|d vr-t j|d |ttd |vr,|d vr(t jd t t|}d|vr d|vr|dz }t|trt|r|pi}ddl }|j||}t!|5} | jdd} | dkrddi}t'| } dddn #1swxYwYt+| ||d|St-|rBt|tsJ|dr|dd}|dr|dd}t3d} g} t3dddlm}m}||t:g} n#t<$rYnwxYw | j|fd|i|pi}nW#tA| $rB|ddi}nt|}d|d<| j|fd|i|pi}YnwxYwt+|||d|S|rtCdt|ttDtFj#fr!t+tI|||d|St|d s1t|ds!d!tK|}tC|t+|||d|S)"a If the filepath_or_buffer is a url, translate and return the buffer. Otherwise passthrough. Parameters ---------- filepath_or_buffer : a url, filepath (str or pathlib.Path), or buffer compression : str or dict, default 'infer' For on-the-fly compression of the output data. If 'infer' and 'filepath_or_buffer' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). Set to ``None`` for no compression. Can also be a dict with key ``'method'`` set to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. encoding : the encoding to use to decode bytes, default is 'utf-8' mode : str, optional storage_options : dict, optional Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to ``urllib.request.Request`` as header options. For other URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are forwarded to ``fsspec.open``. Please see ``fsspec`` and ``urllib`` for more details, and for more examples on storage options refer `here `_. Returns the dataclass IOArgs. writebzDcompression has no effect when passing a non-binary object as input.) stacklevelN)methodw)bz2xz)zutf-16zutf-32z( will not write the byte order mark for a)ziptarzzip and tar do not support mode 'a' properly. This combination will result in multiple files with same name being added to the archive.tr)headerszContent-EncodinggziprT)r7r9r;r=r:zs3a://zs3://zs3n://fsspecbotocore) ClientErrorNoCredentialsErrorr:anonz?storage_options passed with file object or non-fsspec file pathFreadz)Invalid file path or buffer object type: )&rget_compression_methodinfer_compressionhasattrwarningswarnRuntimeWarningr#dictUnicodeWarningrOr8rmrrRequestrrgetr rr5rrreplacer"botocore.exceptionsrrPermissionError ImportErroropentuplerbytesmmaprptype)r7r9r;r:rcompression_method fsspec_moderreq_inforeqcontent_encodingreaderrerr_types_to_retry_with_anonrrfile_objmsgs rE_get_filepath_or_bufferr(sxb((:;;'=[&I&I# *+=?QRR"g&8'BB"sRV R '))    "{+=>>>K t - / / , , ,  N NH N N '))     d{{)^;;  * '))     K +#["8"8s $c** v6H/I/I */R >))*> +,>??#      "F++/67I7/S/SU$?Q:R:RTToo -     s8AF%%F),F)!I55 JJ$J++AK?>K?ruc@ddlm}td||S)z converts an absolute native path to a FILE URL. Parameters ---------- path : a path in native format Returns ------- a valid FILE URL r) pathname2urlzfile:)rrr)rurs rEfile_path_to_urlrs0,+++++ 7LL.. / //rDrrrrrzstd) .tar.tar.gz.tar.bz2.tar.xz.gz.bz2.zip.xzz.zstr."tuple[str | None, CompressionDict]ct|trHt|} |d}n&#t$r}t d|d}~wwxYwi}|}||fS)a Simplifies a compression argument to a compression method string and a mapping containing additional arguments. Parameters ---------- compression : str or mapping If string, specifies the compression method. If mapping, value at key 'method' specifies compression method. Returns ------- tuple of ({compression method}, Optional[str] {compression arguments}, Dict[str, Any]) Raises ------ ValueError on mapping missing 'method' key rz.If mapping, compression must have key 'method'N)rOrrpopKeyErrorr)r;compression_argsrerrs rErrs.+w'') ,, X!1!5!5h!?!?   X X XMNNTW W X( / //s< AAA str | Nonec|dS|dkrt|trd|vr|dd}t|d}t|tsdStD]0\}}||r|cS1dS|tvr|Sddgtt}d|d|}t|) a Get the compression method for filepath_or_buffer. If compression='infer', the inferred compression method is returned. Otherwise, the input compression method is returned unchanged, unless it's invalid, in which case an error is raised. Parameters ---------- filepath_or_buffer : str or file handle File path or object. compression : str or dict, default 'infer' For on-the-fly compression of the output data. If 'infer' and 'filepath_or_buffer' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). Set to ``None`` for no compression. Can also be a dict with key ``'method'`` set to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. Returns ------- string or None Raises ------ ValueError on invalid compression specified. Ninferz::rT)rUnrecognized compression type: z Valid compression types are ) rOr8splitrextension_to_compressionitemslowerendswith_supported_compressionssortedr)r7r; extensionvalidrs rErr:s9Ntg (# . . C4;M3M3M!3!9!9$!?!?!B +,>RVWWW,c22 4'?&D&D&F&F # # "I{!''))229== #"""" #t--- d =V$;<< =E /+ / /', / / S//rD Path | strc|t|j}|std|ddS)z Check if parent directory of a file exists, raise OSError if it does not Parameters ---------- path: Path or str Path to check parent directory of z1Cannot save file into a non-existent directory: ''N)rparentis_dirOSError)rurs rEcheck_parent_directoryrsI$ZZ F ==??VT6TTTUUUVVrD)r9r; memory_maperrorsr path_or_bufris_textLiteral[False]rr1IOHandles[bytes]cdSrWrCrr:r9r;rrrrs rE get_handlers srD)r9r;rrrr Literal[True]IOHandles[str]cdSrWrCrs rErrs SrD!IOHandles[str] | IOHandles[bytes]cdSrWrCrs rErrs ),rDTc: |pd}|pd}t||r d|vr|dz }tj|t|trtj|t |||||}|j} t| |\} }} t| t} t|j } | d}d|vr| rtt | |r3|dkr!|j dd |_ n|dkrd|j vr|xj dz c_ |d krKt| trtjd*| |j d | } ntjd*| |j d | } no|d krddl} | j| fd|j i| } nN|dkrt'| |j fi| } | jj dkr| | | j}t/|dkr.| j| } n|st3d|t3d|n|dkr| d|j t| trt7d*d| i| } nt7d*d| i| } t| t6sJd| jj vr| | | j}t/|dkr'| j|d}|J|} n|st3d|t3d|n|dkrddl}|j| |j fi| } ng|dkrMtAd}d|j vrd|j!d*i| i}nd|j"d*i| i}|j| fd|j i|} nd|}t3|t| trJ| | nnt| trY|j#r(d|j vrt1| |j |j#|d } nt1| |j } | | d }|s7|j d!kr,t| tHrtK| |j#"} n|r|s|st| |j rtM| d#r tM| d$rtM| d%stO| } tQ| |j#|d } | | t|jtp|j) }d|j vr5tM| d&s%tUd'tW|jd(| ,|j)r6t|jtrJ| |jt[| | ||j )S)+a| Get file handle for given path/buffer and mode. Parameters ---------- path_or_buf : str or file handle File path or object. mode : str Mode to open path_or_buf with. encoding : str or None Encoding to use. compression : str or dict, default 'infer' For on-the-fly compression of the output data. If 'infer' and 'path_or_buf' is path-like, then detect compression from the following extensions: '.gz', '.bz2', '.zip', '.xz', '.zst', '.tar', '.tar.gz', '.tar.xz' or '.tar.bz2' (otherwise no compression). Set to ``None`` for no compression. Can also be a dict with key ``'method'`` set to one of {``'zip'``, ``'gzip'``, ``'bz2'``, ``'zstd'``, ``'xz'``, ``'tar'``} and other key-value pairs are forwarded to ``zipfile.ZipFile``, ``gzip.GzipFile``, ``bz2.BZ2File``, ``zstandard.ZstdCompressor``, ``lzma.LZMAFile`` or ``tarfile.TarFile``, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: ``compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}``. May be a dict with key 'method' as compression mode and other keys as compression options if compression mode is 'zip'. Passing compression options as keys in dict is supported for compression modes 'gzip', 'bz2', 'zstd' and 'zip'. memory_map : bool, default False See parsers._parser_params for more information. Only used by read_csv. is_text : bool, default True Whether the type of the content passed to the file/buffer is string or bytes. This is not the same as `"b" not in mode`. If a string content is passed to a binary file/buffer, a wrapper is inserted. errors : str, default 'strict' Specifies how encoding and decoding errors are to be handled. See the errors argument for :func:`open` for a full list of options. storage_options: StorageOptions = None Passed to _get_filepath_or_buffer Returns the dataclass IOHandles rstrictr)r9r;r:rrrrrr)r)filenamer:)fileobjr:rrNr:rzZero files found in ZIP file z9Multiple files found in ZIP file. Only one file per ZIP: rnamerz Zero files found in TAR archive zDMultiple files found in TAR archive. Only one file per TAR archive: r zstandarddctxcctxr)r9rnewlineFrb)r9readablewritableseekablerz1Expected file path name or file-like object, got z type)rHrJrKr;rC)._is_binary_modecodecslookuprOr8 lookup_errorrr7_maybe_memory_maprr;rrr:rrGzipFilerBZ2File _BytesZipFilebufferappendnamelistlenrr setdefault _BytesTarFilegetnames extractfilelzmaLZMAFiler"ZstdDecompressorZstdCompressorr9r_BytesIOWrapperr _IOWrapperrr=rrreverserG)rr:r9r;rrrrioargsrHhandlesis_pathrr zip_namesfilesfiler#r open_argsrrKs rErrsz"7H  xF{D))coo   M(&#$F###% ' F &F #4FJ"G"GFJ%%GF.//"&&x00K $7s6{{+++M &  +--c266FKK F " "s&+'='= KK3 KK & &#&& #' #  ' E ! ! JJJ!S[[#FFE ! !# #F }!S((v&&&"M2244 y>>Q&&#]// @@FF"$%R[%R%RSSS$>2;>>)E ! !  ' ' < < <&#&& &GGFG6FGG '"&fm44 4 44fm(((v&&& ..00u::??!=44U1X>>D+++!FF$%U %U%UVVV$B:?BB) D  KKK"T] #FFF " "-k::Dfk!!#%:T%:%N%N=M%N%NO #%8T%8%L%L;K%L%LM TY[FFBKAACS// !fc*****v FC  ? /s&+55  FF&&+..FvJ  v{d**z&*/M/M* _      ! %4VV[%I%I  ++ (6:.. (6:.. (  ''F _     v v0# 6 6 M&:M  fk'&&"9"9 :122 : : :    OO 2f7=====v0111  &    rDcPeZdZdZeZeddZdfd ZxZ S)_BufferedWriterz Some objects do not support multiple .write() calls (TarFile and ZipFile). This wrapper writes to the underlying buffer on close. rLrMcdSrWrCrXs rEwrite_to_bufferz_BufferedWriter.write_to_buffers'*srDcP|jrdS|jrI|d|j5|dddn #1swxYwYn|jtdS)Nr)closed getbuffernbytesseekrr4rSsuper)rT __class__s rErSz_BufferedWriter.closes ;  F >>   " IIaLLL ' '$$&&& ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' K       sA!!A%(A%rb) r>r?r@rAr rrr4rS __classcell__r;s@rEr2r2sj WYYF***^*          rDr2cBeZdZ ddfd ZddZddZddZxZS)r Nrr rr:Literal['r', 'a', 'w', 'x']r-ReadBuffer[bytes] | WriteBuffer[bytes] | None archive_namerrrLrMc t||_||_t jjd||||d||_dS)N)r r:rrC) r:__init__rAr tarfileTarFiler extend_moder)rTr r:rrArr;s rErCz_BytesTarFile.__init__sq ( (/';( !!$''( (  ( (  rDr8c|dd}|dkr|S|j,t|jj}|dvr|d|dd}|S)Nrr)r)rrr:r )rr rsuffix)rTr:rIs rErFz_BytesTarFile.extend_modesg||C$$ 3;;K 9 $)__+F///---- rDc|jdSt|j}|jdkr|djS|jdvr-|ddjS|jS)z If an explicit archive_name is not given, we still want the file inside the zip file not to be named something.tar, because that causes confusion (GH39465). Nrr))rrr)r rrI with_suffixrTrs rEinfer_filenamez_BytesTarFile.infer_filenames} 9 4 ?? ?f $ $''++0 0 _ B B B''++77;;@ @}rDc|jp|pd}tj|}t ||_|j||dS)Nr)r ) rArMrDTarInforgetvaluesizeraddfile)rTrAtarinfos rEr4z_BytesTarFile.write_to_buffer+sg(JD,?,?,A,AJU /|4444==??++  GT*****rD)NrNN) r rr:r?rr@rArrrrLrM)r:r8rLr8rLrrb)r>r?r@rCrFrMr4r<r=s@rEr r s ,/AE#'        .    ++++++++rDr c4eZdZ ddfd Zdd ZddZxZS)rNr/1FilePath | ReadBuffer[bytes] | WriteBuffer[bytes]r:r8rArrrrLrMc t|dd}||_|dt jt j||fi||_dS)Nrr)r;) r:rCrrArzipfile ZIP_DEFLATEDZipFiler)rTr/r:rArr;s rErCz_BytesZipFile.__init__4sz ||C$$(-)=>>> (/ $( (  ( (  rDct|jjtjt frEt |jj}|jdkr|dj S|j SdS)z If an explicit archive_name is not given, we still want the file inside the zip file not to be named something.zip, because that causes confusion (GH39465). rr)N) rOrrrtrr8rrIrKr rLs rErMz_BytesZipFile.infer_filenameIse dk*R[#,> ? ? !DK011H&((++B//44= trDc|jp|pd}|j||dS)Nr)rArMrwritestrrP)rTrAs rEr4z_BytesZipFile.write_to_bufferUsF(JD,?,?,A,AJU  \4==??;;;;;rDrW) r/rVr:r8rArrrrLrMrTrb)r>r?r@rCrMr4r<r=s@rErr3so $(        *    <<<<<<<r?r@rCrcrrrrCrDrEr(r([sx****  rDr(c*eZdZdddZdd ZdddZdS)r'rrStringIO | TextIOBaser9r8rLrMc0||_||_d|_dS)NrD)rr9overflow)rTrr9s rErCz_BytesIOWrapper.__init__{s    rDattrrc,t|j|SrWra)rTrms rErcz_BytesIOWrapper.__getattr__rdrDn int | Nonerc |jJ|j||j}|j|z}||dks|t |kr d|_|S|d|}||d|_|S)NrrD)rrencoder9rlr)rTrp bytestringcombined_bytestring to_returns rErz_BytesIOWrapper.reads{&&&[%%a((// >> "mj8 9Ac*=&>&>!>!>DM& &+BQB/I/3DM rDN)r)rrjr9r8rLrM)rmr8rLr)ro)rprqrLr)r>r?r@rCrcrrCrDrEr'r'xsZ****       rDr'rHr6/tuple[str | BaseBuffer, bool, list[BaseBuffer]]c4g}|t|dpt|tz}|s|||fStt|}t|tr%t |d}|| ttj| dtj }t|D]}| n+#t|D]}| wxYw|||gfS)zTry to memory map file/buffer.filenorr)access) rrOr8rr!rrr(rry ACCESS_READreversedrS)rHrr+wrappeds rErrs1!#G'&(++Fz&#/F/FFJ +z7**- ( (F&#fd##v I '     w''  F LLNNNN hw''  F LLNNNN  J ))s AC))(Dcd}t|}t|ts|S tj|}n#t tf$rYnwxYw|S)zTest whether file exists.F)rrOr8rtruexistsrr)r7rs rE file_existsrss F'(:;; (# . .   233 z "     MsA AAcd|vsd|vrd|vStjtjtjf}t t ||rdSt |tpdt|d|vS)z+Whether the handle is opened in binary moderrFr:) r StreamWriter StreamReaderStreamReaderWriter issubclassrrO_get_binary_io_classesrb)rHr: text_classess rErrs d{{cTkkd{ ! L $v,, --u f466 7 7 3'CC<rDtuple[type, ...]cttf}tdd}|R|d5}|t |fz }dddn #1swxYwY|S)z!IO classes that that expect bytesr ignore)rNrD)r r r"r% stream_readerr)binary_classesrrs rErrs)7 'BN &k( C C CD   " " $ $ 2 23 7 7 .6 tF||o -N . . . . . . . . . . . . . . . s A))A-0A-columnsSequence[Hashable] | MultiIndex index_colbool | Sequence[int] | Nonec|t|trtnt|tt|o0t|t ot fd|DS)a Check whether or not the `columns` parameter could be converted into a MultiIndex. Parameters ---------- columns : array-like Object which may or may not be convertible into a MultiIndex index_col : None, bool or list, optional Column or columns to use as the (possibly hierarchical) index Returns ------- bool : Whether or not columns could become a MultiIndex Nc3JK|]}|vt|tVdSrW)rOr)r{c index_columnss rEr}z+is_potential_multi_index.. s7PP-9O9O 1e$$9O9O9O9OPPrD)rOr<setrr(r)rrrs @rEis_potential_multi_indexrs&Jy$77 I  G  Q7M22 2 Q PPPPgPPP P P  rDnamesSequence[Hashable]is_potential_multiindexcNt|}tt}t|D]q\}}||}|dkrQ|dz||<|r2t |t sJg|dd|dd|R}n|d|}||}|dkQ|||<|dz||<r|S)a: Rename column names if duplicates exist. Currently the renaming is done by appending a period and an autonumeric, but a custom pattern may be supported in the future. Examples -------- >>> dedup_names(["x", "y", "x", "x"], is_potential_multiindex=False) ['x', 'y', 'x.1', 'x.2'] rr Nro.)rerr~ enumeraterOr)rrcountsr|col cur_counts rE dedup_namesr s KKE)4S)9)9FE""$$33K !mm#a-F3K& +!#u-----;CRC;SW":":y":":;;**y**s I!mma!ms LrD)rfrgrLr<)r7r8rLr8)r7r*rLr*)r7rrrLrr)rwrgrLrM).)r7r/rr<rLr8)r7r*rr<rLr*)F)r7rrr<rLrr)rrrrrLr)rfrrLr<)rNrN) r7rr9r8r;rr:r8rrrLr5)rur8rLr8)r;r.rLr)r7rr;rrLr)rurrLrM)rrr:r8r9rr;r.rr<rrrrrr1rLr)rrr:r8r9rr;r.rr<rrrrrr1rLr)rrr:r8r9rr;r.rr<rr<rrrr1rLr)rrr:r8r9rr;rrr<rr<rrrrrLr)rHr6rr<rLrw)r7rrLr<)rHrr:r8rLr<)rLrrW)rrrrrLr<)rrrr<rLr)mrA __future__rabcrrr collectionsrcollections.abcrrr rc functoolsrior r r r rrrrtpathlibrrerDtypingrrrrrrrrrr urllib.parserrrirrrrrXpandas._typingr r!pandas.compat._optionalr"pandas.util._exceptionsr#pandas.core.dtypes.commonr$r%r&r'pandas.core.dtypes.genericr(rrkdiscardcompilerr*typesr,r-r.r/r0r1r2pandasr3 dataclassr5rGrmrprrrrrrrvaluesrrrrrr2r rr(r'rrr lru_cacherrrrCrDrErs0"""""" ######                            ?>>>>>444444 544444c-+- ;<< B bj!WXXgm:666  "######"!!!!!          ........b0000$ 555 5 EEE E&CCCC: """"""rD