[ 
https://issues.apache.org/jira/browse/ARROW-2172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16369747#comment-16369747
 ] 

ASF GitHub Bot commented on ARROW-2172:
---------------------------------------

pitrou commented on a change in pull request #1628: ARROW-2172: [C++/Python] 
Fix converting from Numpy array with non-natural stride
URL: https://github.com/apache/arrow/pull/1628#discussion_r169223711
 
 

 ##########
 File path: cpp/src/arrow/python/numpy_to_arrow.cc
 ##########
 @@ -554,12 +554,22 @@ Status StaticCastBuffer(const Buffer& input, const 
int64_t length, MemoryPool* p
   return Status::OK();
 }
 
-template <typename T, typename T2>
-void CopyStrided(T* input_data, int64_t length, int64_t stride, T2* 
output_data) {
+template <typename T>
+void CopyStridedBytewise(int8_t* input_data, int64_t length, int64_t stride,
+                         T* output_data) {
+  // Passing input_data as non-const is a concession to PyObject*
+  for (int64_t i = 0; i < length; ++i) {
+    memcpy(output_data + i, input_data, sizeof(T));
+    input_data += stride;
 
 Review comment:
   In normal use, it probably is, but you can create weird arrays using 
`stride_tricks`: 
https://docs.scipy.org/doc/numpy/reference/generated/numpy.lib.stride_tricks.as_strided.html
   
   That said, I don't think it makes a problem here, does it?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] Incorrect conversion from Numpy array when stride % itemsize != 0
> --------------------------------------------------------------------------
>
>                 Key: ARROW-2172
>                 URL: https://issues.apache.org/jira/browse/ARROW-2172
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 0.8.0
>            Reporter: Antoine Pitrou
>            Priority: Major
>              Labels: pull-request-available
>
> In the example below, the input array has a stride that's not a multiple of 
> the itemsize:
> {code:python}
> >>> data = np.array([(42, True), (43, False)],
> ...:                dtype=[('x', np.int32), ('y', np.bool_)])
> ...:                
> ...:                                        
> >>> data['x']
> array([42, 43], dtype=int32)
> >>> pa.array(data['x'], type=pa.int32())
> <pyarrow.lib.Int32Array object at 0x7ff60a8415e8>
> [
>   42,
>   11009
> ]
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to