You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2018/07/28 23:59:58 UTC

[arrow] branch master updated: ARROW-2700: [Python] Add simple examples to Array.cast docstring

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new b56d269  ARROW-2700: [Python]  Add simple examples to Array.cast docstring
b56d269 is described below

commit b56d26946f67cde6bcce1bff0012a829b493a527
Author: Korn, Uwe <Uw...@blue-yonder.com>
AuthorDate: Sat Jul 28 19:59:51 2018 -0400

    ARROW-2700: [Python]  Add simple examples to Array.cast docstring
    
    Author: Korn, Uwe <Uw...@blue-yonder.com>
    
    Closes #2335 from xhochy/ARROW-2700 and squashes the following commits:
    
    292614f2 <Korn, Uwe> ARROW-2700:   Add simple examples to Array.cast docstring
---
 python/pyarrow/array.pxi | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi
index 82e4aec..d59bb05 100644
--- a/python/pyarrow/array.pxi
+++ b/python/pyarrow/array.pxi
@@ -372,7 +372,39 @@ cdef class Array:
 
     def cast(self, object target_type, safe=True):
         """
-        Cast array values to another data type
+        Cast array values to another data type.
+
+        Example
+        -------
+
+        >>> from datetime import datetime
+        >>> import pyarrow as pa
+        >>> arr = pa.array([datetime(2010, 1, 1), datetime(2015, 1, 1)])
+        >>> arr.type
+        TimestampType(timestamp[us])
+
+        You can use ``pyarrow.DataType`` objects to specify the target type:
+
+        >>> arr.cast(pa.timestamp('ms'))
+        <pyarrow.lib.TimestampArray object at 0x10420eb88>
+        [
+          1262304000000,
+          1420070400000
+        ]
+        >>> arr.cast(pa.timestamp('ms')).type
+        TimestampType(timestamp[ms])
+
+        Alternatively, it is also supported to use the string aliases for these
+        types:
+
+        >>> arr.cast('timestamp[ms]')
+        <pyarrow.lib.TimestampArray object at 0x10420eb88>
+        [
+          1262304000000,
+          1420070400000
+        ]
+        >>> arr.cast('timestamp[ms]').type
+        TimestampType(timestamp[ms])
 
         Parameters
         ----------