Bases: _PandasConvertible
An array-like composed from a (possibly empty) collection of pyarrow.Arrays
Warning
Do not call this classâs constructor directly.
Examples
To construct a ChunkedArray object use pyarrow.chunked_array()
:
>>> import pyarrow as pa >>> pa.chunked_array([], type=pa.int8()) <pyarrow.lib.ChunkedArray object at ...> [ ... ]
>>> pa.chunked_array([[2, 2, 4], [4, 5, 100]]) <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> isinstance(pa.chunked_array([[2, 2, 4], [4, 5, 100]]), pa.ChunkedArray) True
Methods
Attributes
Cast array values to another data type
See pyarrow.compute.cast()
for usage.
DataType
, None
Type to cast array to.
True
Whether to check for conversion errors such as overflow.
CastOptions
, default None
Additional checks pass by CastOptions
Array
or ChunkedArray
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.type DataType(int64)
Change the data type of an array:
>>> n_legs_seconds = n_legs.cast(pa.duration('s')) >>> n_legs_seconds.type DurationType(duration[s])
Select a chunk by its index.
int
pyarrow.Array
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, None], [4, 5, 100]]) >>> n_legs.chunk(1) <pyarrow.lib.Int64Array object at ...> [ 4, 5, 100 ]
Convert to a list of single-chunked arrays.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, None], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, null ], [ 4, 5, 100 ] ] >>> n_legs.chunks [<pyarrow.lib.Int64Array object at ...> [ 2, 2, null ], <pyarrow.lib.Int64Array object at ...> [ 4, 5, 100 ]]
Flatten this ChunkedArray into a single non-chunked array.
MemoryPool
, default None
For memory allocations, if required, otherwise use default pool
Array
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.combine_chunks() <pyarrow.lib.Int64Array object at ...> [ 2, 2, 4, 4, 5, 100 ]
Compute dictionary-encoded representation of array.
See pyarrow.compute.dictionary_encode()
for full usage.
str
, default âmaskâ
How to handle null entries.
ChunkedArray
A dictionary-encoded version of this array.
Examples
>>> import pyarrow as pa >>> animals = pa.chunked_array(( ... ["Flamingo", "Parrot", "Dog"], ... ["Horse", "Brittle stars", "Centipede"] ... )) >>> animals.dictionary_encode() <pyarrow.lib.ChunkedArray object at ...> [ ... -- dictionary: [ "Flamingo", "Parrot", "Dog", "Horse", "Brittle stars", "Centipede" ] -- indices: [ 0, 1, 2 ], ... -- dictionary: [ "Flamingo", "Parrot", "Dog", "Horse", "Brittle stars", "Centipede" ] -- indices: [ 3, 4, 5 ] ]
Remove missing values from a chunked array. See pyarrow.compute.drop_null()
for full description.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, None], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, null ], [ 4, 5, 100 ] ] >>> n_legs.drop_null() <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2 ], [ 4, 5, 100 ] ]
Return whether the contents of two chunked arrays are equal.
pyarrow.ChunkedArray
Chunked array to compare against.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> animals = pa.chunked_array(( ... ["Flamingo", "Parrot", "Dog"], ... ["Horse", "Brittle stars", "Centipede"] ... )) >>> n_legs.equals(n_legs) True >>> n_legs.equals(animals) False
Replace each null element in values with fill_value.
See pyarrow.compute.fill_null()
for full usage.
any
The replacement value for null entries.
Array
or ChunkedArray
A new array with nulls replaced by the given value.
Examples
>>> import pyarrow as pa >>> fill_value = pa.scalar(5, type=pa.int8()) >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.fill_null(fill_value) <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4, 4, 5, 100 ] ]
Select values from the chunked array.
See pyarrow.compute.filter()
for full usage.
Array
or array-like
The boolean mask to filter the chunked array with.
str
, default âdropâ
How nulls in the mask should be handled.
Array
or ChunkedArray
An array of the same type, with only the elements selected by the boolean mask.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> mask = pa.array([True, False, None, True, False, True]) >>> n_legs.filter(mask) <pyarrow.lib.ChunkedArray object at ...> [ [ 2 ], [ 4, 100 ] ] >>> n_legs.filter(mask, null_selection_behavior="emit_null") <pyarrow.lib.ChunkedArray object at ...> [ [ 2, null ], [ 4, 100 ] ]
Flatten this ChunkedArray. If it has a struct type, the column is flattened into one array per struct field.
MemoryPool
, default None
For memory allocations, if required, otherwise use default pool
list
of ChunkedArray
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> c_arr = pa.chunked_array(n_legs.value_counts()) >>> c_arr <pyarrow.lib.ChunkedArray object at ...> [ -- is_valid: all not null -- child 0 type: int64 [ 2, 4, 5, 100 ] -- child 1 type: int64 [ 2, 2, 1, 1 ] ] >>> c_arr.flatten() [<pyarrow.lib.ChunkedArray object at ...> [ [ 2, 4, 5, 100 ] ], <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 1, 1 ] ]] >>> c_arr.type StructType(struct<values: int64, counts: int64>) >>> n_legs.type DataType(int64)
DEPRECATED, use pyarrow.ChunkedArray.to_string
dict
str
The sum of bytes in each buffer referenced by the chunked array.
An array may only reference a portion of a buffer. This method will overestimate in this case and return the byte size of the entire buffer.
If a buffer is referenced multiple times then it will only be counted once.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.get_total_buffer_size() 49
Find the first index of a value.
See pyarrow.compute.index()
for full usage.
Scalar
or object
The value to look for in the array.
int
, optional
The start index where to look for value.
int
, optional
The end index where to look for value.
MemoryPool
, optional
A memory pool for potential memory allocations.
Int64Scalar
The index of the value in the array (-1 if not found).
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.index(4) <pyarrow.Int64Scalar: 2> >>> n_legs.index(4, start=3) <pyarrow.Int64Scalar: 3>
Whether all chunks in the ChunkedArray are CPU-accessible.
Return boolean array indicating the NaN values.
Examples
>>> import pyarrow as pa >>> import numpy as np >>> arr = pa.chunked_array([[2, np.nan, 4], [4, None, 100]]) >>> arr.is_nan() <pyarrow.lib.ChunkedArray object at ...> [ [ false, true, false, false, null, false ] ]
Return boolean array indicating the null values.
False
)
Whether floating-point NaN values should also be considered null.
Array
or ChunkedArray
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.is_null() <pyarrow.lib.ChunkedArray object at ...> [ [ false, false, false, false, true, false ] ]
Return boolean array indicating the non-null values.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.is_valid() <pyarrow.lib.ChunkedArray object at ...> [ [ true, true, true ], [ true, false, true ] ]
Convert to an iterator of ChunkArrays.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> for i in n_legs.iterchunks(): ... print(i.null_count) ... 0 1
Return length of a ChunkedArray.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.length() 6
Total number of bytes consumed by the elements of the chunked array.
In other words, the sum of bytes from all buffer ranges referenced.
Unlike get_total_buffer_size this method will account for array offsets.
If buffers are shared between arrays then the shared portion will only be counted multiple times.
The dictionary of dictionary arrays will always be counted in their entirety even if the array only references a portion of the dictionary.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.nbytes 49
Number of null entries
int
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.null_count 1
Number of underlying chunks.
int
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, None], [4, 5, 100]]) >>> n_legs.num_chunks 2
Compute zero-copy slice of this ChunkedArray
int
, default 0
Offset from start of array to slice
int
, default None
Length of slice (default is until end of batch starting from offset)
ChunkedArray
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.slice(2,2) <pyarrow.lib.ChunkedArray object at ...> [ [ 4 ], [ 4 ] ]
Sort the ChunkedArray
str
, default âascendingâ
Which order to sort values in. Accepted values are âascendingâ, âdescendingâ.
dict
, optional
Additional sorting options. As allowed by SortOptions
ChunkedArray
Select values from the chunked array.
See pyarrow.compute.take()
for full usage.
Array
or array-like
The indices in the array whose values will be returned.
Array
or ChunkedArray
An array with the same datatype, containing the taken values.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.take([1,4,5]) <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 5, 100 ] ]
Return a NumPy copy of this array (experimental).
False
Introduced for signature consistence with pyarrow.Array.to_numpy. This must be False here since NumPy arraysâ buffer must be contiguous.
numpy.ndarray
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.to_numpy() array([ 2, 2, 4, 4, 5, 100])
Convert to a pandas-compatible NumPy array or DataFrame, as appropriate
MemoryPool
, default None
Arrow MemoryPool to use for allocations. Uses the default memory pool if not passed.
list
, default empty
List of fields that should be returned as pandas.Categorical. Only applies to table-like data structures.
False
Encode string (UTF8) and binary types to pandas.Categorical.
False
Raise an ArrowException if this function call would require copying the underlying data.
False
Cast integers with nulls to objects
True
Cast dates to objects. If False, convert to datetime64 dtype with the equivalent time unit (if supported). Note: in pandas version < 2.0, only datetime64[ns] conversion is supported.
False
Cast non-nanosecond timestamps (np.datetime64) to objects. This is useful in pandas version 1.x if you have timestamps that donât fit in the normal date range of nanosecond timestamps (1678 CE-2262 CE). Non-nanosecond timestamps are supported in pandas version 2.0. If False, all timestamps are converted to datetime64 dtype.
True
Whether to parallelize the conversion using multiple threads.
True
Do not create multiple copies Python objects when created, to save on memory use. Conversion will be slower.
False
If True, do not use the âpandasâ metadata to reconstruct the DataFrame index, if present
True
For certain data types, a cast is needed in order to store the data in a pandas DataFrame or Series (e.g. timestamps are always stored as nanoseconds in pandas). This option controls whether it is a safe cast or not.
False
If True, generate one internal âblockâ for each column when creating a pandas.DataFrame from a RecordBatch or Table. While this can temporarily reduce memory note that various pandas operations can trigger âconsolidationâ which may balloon memory use.
False
EXPERIMENTAL: If True, attempt to deallocate the originating Arrow memory while converting the Arrow object to pandas. If you use the object after calling to_pandas with this option it will crash your program.
Note that you may not see always memory usage improvements. For example, if multiple columns share an underlying allocation, memory canât be freed until all columns are converted.
str
, optional, default None
Valid values are None, âlossyâ, or âstrictâ. The default behavior (None), is to convert Arrow Map arrays to Python association lists (list-of-tuples) in the same order as the Arrow Map, as in [(key1, value1), (key2, value2), â¦].
If âlossyâ or âstrictâ, convert Arrow Map arrays to native Python dicts. This can change the ordering of (key, value) pairs, and will deduplicate multiple keys, resulting in a possible loss of data.
If âlossyâ, this key deduplication results in a warning printed when detected. If âstrictâ, this instead results in an exception being raised when detected.
None
A function mapping a pyarrow DataType to a pandas ExtensionDtype. This can be used to override the default pandas type for conversion of built-in pyarrow types or in absence of pandas_metadata in the Table schema. The function receives a pyarrow DataType and is expected to return a pandas ExtensionDtype or None
if the default conversion should be used for that type. If you have a dictionary mapping, you can pass dict.get
as function.
False
Only applicable to pandas version >= 2.0. A legacy option to coerce date32, date64, duration, and timestamp time units to nanoseconds when converting to pandas. This is the default behavior in pandas version 1.x. Set this option to True if youâd like to use this coercion when using pandas version >= 2.0 for backwards compatibility (not recommended otherwise).
pandas.Series
or pandas.DataFrame
depending on type
of object
Examples
>>> import pyarrow as pa >>> import pandas as pd
Convert a Table to pandas DataFrame:
>>> table = pa.table([ ... pa.array([2, 4, 5, 100]), ... pa.array(["Flamingo", "Horse", "Brittle stars", "Centipede"]) ... ], names=['n_legs', 'animals']) >>> table.to_pandas() n_legs animals 0 2 Flamingo 1 4 Horse 2 5 Brittle stars 3 100 Centipede >>> isinstance(table.to_pandas(), pd.DataFrame) True
Convert a RecordBatch to pandas DataFrame:
>>> import pyarrow as pa >>> n_legs = pa.array([2, 4, 5, 100]) >>> animals = pa.array(["Flamingo", "Horse", "Brittle stars", "Centipede"]) >>> batch = pa.record_batch([n_legs, animals], ... names=["n_legs", "animals"]) >>> batch pyarrow.RecordBatch n_legs: int64 animals: string ---- n_legs: [2,4,5,100] animals: ["Flamingo","Horse","Brittle stars","Centipede"] >>> batch.to_pandas() n_legs animals 0 2 Flamingo 1 4 Horse 2 5 Brittle stars 3 100 Centipede >>> isinstance(batch.to_pandas(), pd.DataFrame) True
Convert a Chunked Array to pandas Series:
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.to_pandas() 0 2 1 2 2 4 3 4 4 5 5 100 dtype: int64 >>> isinstance(n_legs.to_pandas(), pd.Series) True
Convert to a list of native Python objects.
str
, optional, default None
Valid values are None, âlossyâ, or âstrictâ. The default behavior (None), is to convert Arrow Map arrays to Python association lists (list-of-tuples) in the same order as the Arrow Map, as in [(key1, value1), (key2, value2), â¦].
If âlossyâ or âstrictâ, convert Arrow Map arrays to native Python dicts.
If âlossyâ, whenever duplicate keys are detected, a warning will be printed. The last seen value of a duplicate key will be in the Python dictionary. If âstrictâ, this instead results in an exception being raised when detected.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, None, 100]]) >>> n_legs.to_pylist() [2, 2, 4, 4, None, 100]
Render a âpretty-printedâ string representation of the ChunkedArray
int
How much to indent right the content of the array, by default 0
.
int
How many items to preview within each chunk at the begin and end of the chunk when the chunk is bigger than the window. The other elements will be ellipsed.
int
How many chunks to preview at the begin and end of the array when the array is bigger than the window. The other elements will be ellipsed. This setting also applies to list columns.
If the array should be rendered as a single line of text or if each element should be on its own line.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.to_string(skip_new_lines=True) '[[2,2,4],[4,5,100]]'
Return data type of a ChunkedArray.
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs.type DataType(int64)
Unify dictionaries across all chunks.
This method returns an equivalent chunked array, but where all chunks share the same dictionary values. Dictionary indices are transposed accordingly.
If there are no dictionaries in the chunked array, it is returned unchanged.
MemoryPool
, default None
For memory allocations, if required, otherwise use default pool
ChunkedArray
Examples
>>> import pyarrow as pa >>> arr_1 = pa.array(["Flamingo", "Parrot", "Dog"]).dictionary_encode() >>> arr_2 = pa.array(["Horse", "Brittle stars", "Centipede"]).dictionary_encode() >>> c_arr = pa.chunked_array([arr_1, arr_2]) >>> c_arr <pyarrow.lib.ChunkedArray object at ...> [ ... -- dictionary: [ "Flamingo", "Parrot", "Dog" ] -- indices: [ 0, 1, 2 ], ... -- dictionary: [ "Horse", "Brittle stars", "Centipede" ] -- indices: [ 0, 1, 2 ] ] >>> c_arr.unify_dictionaries() <pyarrow.lib.ChunkedArray object at ...> [ ... -- dictionary: [ "Flamingo", "Parrot", "Dog", "Horse", "Brittle stars", "Centipede" ] -- indices: [ 0, 1, 2 ], ... -- dictionary: [ "Flamingo", "Parrot", "Dog", "Horse", "Brittle stars", "Centipede" ] -- indices: [ 3, 4, 5 ] ]
Compute distinct elements in array
pyarrow.Array
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.unique() <pyarrow.lib.Int64Array object at ...> [ 2, 4, 5, 100 ]
Perform validation checks. An exception is raised if validation fails.
By default only cheap validation checks are run. Pass full=True for thorough validation checks (potentially O(n)).
False
If True, run expensive checks, otherwise cheap checks only.
ArrowInvalid
Compute counts of unique elements in array.
An
array
of <input type
âValuesâ, int64_t
âCountsâ> structs
Examples
>>> import pyarrow as pa >>> n_legs = pa.chunked_array([[2, 2, 4], [4, 5, 100]]) >>> n_legs <pyarrow.lib.ChunkedArray object at ...> [ [ 2, 2, 4 ], [ 4, 5, 100 ] ] >>> n_legs.value_counts() <pyarrow.lib.StructArray object at ...> -- is_valid: all not null -- child 0 type: int64 [ 2, 4, 5, 100 ] -- child 1 type: int64 [ 2, 2, 1, 1 ]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4