This is an automated email from the ASF dual-hosted git repository.
westonpace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new e6faed2 ARROW-13717: Creating arrays recipe (#63)
e6faed2 is described below
commit e6faed2a3eae8aedb3b3be5664068fbb980655f6
Author: Alessandro Molina <[email protected]>
AuthorDate: Tue Sep 7 20:02:15 2021 +0200
ARROW-13717: Creating arrays recipe (#63)
* Creating arrays recipe
* shorten pandas too for consistency
---
python/source/create.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/python/source/create.rst b/python/source/create.rst
index acf25e2..67ce6ef 100644
--- a/python/source/create.rst
+++ b/python/source/create.rst
@@ -7,6 +7,68 @@ Tensors and all other Arrow entities.
.. contents::
+Creating Arrays
+===============
+
+Arrow keeps data in continuous arrays optimised for memory footprint
+and SIMD analyses. In Python it's possible to build :class:`pyarrow.Array`
+starting from Python ``lists`` (or sequence types in general),
+``numpy`` arrays and ``pandas`` Series.
+
+.. testcode::
+
+ import pyarrow as pa
+
+ array = pa.array([1, 2, 3, 4, 5])
+
+.. testcode::
+
+ print(array)
+
+.. testoutput::
+
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ]
+
+Arrays can also provide a ``mask`` to specify which values should
+be considered nulls
+
+.. testcode::
+
+ import numpy as np
+
+ array = pa.array([1, 2, 3, 4, 5],
+ mask=np.array([True, False, True, False, True]))
+
+ print(array)
+
+.. testoutput::
+
+ [
+ null,
+ 2,
+ null,
+ 4,
+ null
+ ]
+
+When building arrays from ``numpy`` or ``pandas``, Arrow will leverage
+optimized code paths that rely on the internal in-memory representation
+of the data by ``numpy`` and ``pandas``
+
+.. testcode::
+
+ import numpy as np
+ import pandas as pd
+
+ array_from_numpy = pa.array(np.arange(5))
+ array_from_pandas = pa.array(pd.Series([1, 2, 3, 4, 5]))
+
Creating Tables
===============