e}i!XddlmZddlmZmZmZmZddlZddl m Z GddZ dS)) annotations)AnyIterableOptionalSequenceN)_PyArrowColumnceZdZdZ d(d)d Z d(d*d Zed+dZd,dZd,dZ d,dZ d-dZ d.dZ d/dZ d0dZd1dZd2d"Z d3d4d'Zd#S)5_PyArrowDataFramea2 A data frame class, with only the methods required by the interchange protocol defined. A "data frame" represents an ordered collection of named columns. A column's "name" must be a unique string. Columns may be accessed by name or by position. This could be a public data frame class, or an object with the methods and attributes defined on this DataFrame class could be returned from the ``__dataframe__`` method of a public data frame class in a library adhering to the dataframe interchange protocol specification. FTdfpa.Table | pa.RecordBatch nan_as_nullbool allow_copyreturnNonecV||_|durtd||_||_dS)z Constructor - an instance of this (private) class is returned from `pa.Table.__dataframe__` or `pa.RecordBatch.__dataframe__`. TzKnan_as_null=True currently has no effect, use the default nan_as_null=FalseN)_df RuntimeError _nan_as_null _allow_copy)selfr r rs KC:\PYTHON\_runtimes\venv\Lib\site-packages\pyarrow/interchange/dataframe.py__init__z_PyArrowDataFrame.__init__.sG $  4 (%c.t|j||S)a Construct a new exchange object, potentially changing the parameters. ``nan_as_null`` is a keyword intended for the consumer to tell the producer to overwrite null values in the data with ``NaN``. It is intended for cases where the consumer does not support the bit mask or byte mask that is the producer's native representation. ``allow_copy`` is a keyword that defines whether or not the library is allowed to make a copy of the data. For example, copying data would be necessary if a library supports strided buffers, given that this protocol specifies contiguous buffers. )r r)rr rs r __dataframe__z_PyArrowDataFrame.__dataframe__Cs!; CCCrdict[str, Any]c|jjjr/d|jjjD}|SiS)a! The metadata for the data frame, as a dictionary with string keys. The contents of `metadata` may be anything, they are meant for a library to store information that it needs to, e.g., roundtrip losslessly or for two implementations to share data that is not (yet) part of the interchange protocol specification. For avoiding collisions with other entries, please add name the keys with the name of the library followed by a period and the desired name, e.g, ``pandas.indexcol``. cli|]1\}}d|dz|d2S)zpyarrow.utf8)decode).0kvs r z._PyArrowDataFrame.metadata..asQMMM#'1a *AHHV,<,<N>NMMMr)rschemametadataitems)rschema_metadatas rr'z_PyArrowDataFrame.metadataSsT 8? # MM+/8?+C+I+I+K+KMMMO" "Irintc|jjS)z@ Return the number of columns in the DataFrame. )r num_columnsrs rr,z_PyArrowDataFrame.num_columnsgsx##rc|jjS)zK Return the number of rows in the DataFrame, if available. )rnum_rowsr-s rr/z_PyArrowDataFrame.num_rowsmsx  rct|jtjrdS|j}t |S)zH Return the number of chunks the DataFrame consists of. ) isinstancerpa RecordBatch to_batcheslen)rbatchess r num_chunksz_PyArrowDataFrame.num_chunksss@ dh / / 1 h))++Gw<< r Iterable[str]c$|jjjS)z? Return an iterator yielding the column names. )rr&namesr-s r column_namesz_PyArrowDataFrame.column_namessx$$rirc^t|j||jS)z> Return the column at the indicated position. rrrcolumnr)rr=s r get_columnz_PyArrowDataFrame.get_columns1dhooa00)-)9;;; ;rnamestrc^t|j||jS)zE Return the column whose name is the indicated name. r?r@)rrCs rget_column_by_namez$_PyArrowDataFrame.get_column_by_names1dhood33)-)9;;; ;rIterable[_PyArrowColumn]c4fdjjDS)z: Return an iterator yielding the columns. c<g|]}t|jS)r?)rr)r"colrs r z1_PyArrowDataFrame.get_columns..s9    34+; < < <   r)rcolumnsr-s`r get_columnsz_PyArrowDataFrame.get_columnss3    x'    rindices Sequence[int]ct|jt||j|jS)zS Create a new DataFrame by selecting a subset of columns by index. r rselectlistrr)rrNs rselect_columnsz _PyArrowDataFrame.select_columnss7! HOODMM * *D,=t?O   rr; Sequence[str]ct|jt||j|jS)zR Create a new DataFrame by selecting a subset of columns by name. rQ)rr;s rselect_columns_by_namez(_PyArrowDataFrame.select_columns_by_names7 ! HOODKK ( ($*;T=M   rNn_chunks Optional[int]Iterable[_PyArrowDataFrame]c|r |dkr|z}|zdkr|dz }tjtjrj|}nGg}t d||z|D]0}|j||1t||dz kr4|tj ggjj nAtjtjrj}njg}fd|D}|S)a Return an iterator yielding the chunks. By default (None), yields the chunks that the data is stored as by the producer. If given, ``n_chunks`` must be a multiple of ``self.num_chunks()``, meaning the producer must subdivide each chunk before yielding it. Note that the producer must ensure that all columns are chunked the same way. r1r) max_chunksize)r&cFg|]}t|jjS)r rr)r"batchrs rrKz0_PyArrowDataFrame.get_chunks..sC***&e&*&7&*&688***r) r/r2rr3Tabler5rangeappendslicer6 record_batchr&)rrX chunk_sizer7startiterators` r get_chunksz_PyArrowDataFrame.get_chunkssk  %1 H4J}})Q..a $(BH-- F(--J-GG"1j8&;ZHHFFENN48>>%#D#DEEEE7||x!|++rtDHOLLLMMM$(BH-- %(--//8*****")***r)FT)r r r rrrrr)r rrrrr )rr)rr*)rr9)r=r*rr)rCrDrr)rrG)rNrOrr )r;rUrr )N)rXrYrrZ)__name__ __module__ __qualname____doc__rrpropertyr'r,r/r8r<rBrFrMrTrWrhr^rrr r sU   "&&&&&,=ADDDDD X&$$$$ !!!!     %%%% ;;;;;;;;            )-)))))))rr ) __future__rtypingrrrrpyarrowr3pyarrow.interchange.columnrr r^rrrrs$#"""""555555zzzzzzzzzzr