From 26709885687c782ba30ecbc7a0685cfc0eff55ff Mon Sep 17 00:00:00 2001
From: Stefan Wunsch <stefan.wunsch@cern.ch>
Date: Wed, 13 Mar 2019 16:10:03 +0100
Subject: [PATCH] [PyROOT] Improve documentation of data pointer for array
 interface

---
 bindings/pyroot/src/Pythonize.cxx                             | 4 +++-
 .../PyROOT/python/ROOT/pythonization/_rvec.py                 | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/bindings/pyroot/src/Pythonize.cxx b/bindings/pyroot/src/Pythonize.cxx
index 483cbfeddab..bd73790b141 100644
--- a/bindings/pyroot/src/Pythonize.cxx
+++ b/bindings/pyroot/src/Pythonize.cxx
@@ -2334,7 +2334,9 @@ namespace {
 
       // Pointer
       auto ptr = reinterpret_cast<unsigned long long>(cobj->data());
-      if (cobj->empty()) ptr = 1; // Numpy breaks for data pointer of 0 even though the array is empty.
+      // Numpy breaks for data pointer of 0 even though the array is empty.
+      // We set the pointer to 1 but the value itself is arbitrary and never accessed.
+      if (cobj->empty()) ptr = 1;
       auto pyptr = PyLong_FromUnsignedLongLong(ptr);
       auto pydata = PyTuple_Pack(2, pyptr, Py_False);
       PyDict_SetItemString(dict, "data", pydata);
diff --git a/bindings/pyroot_experimental/PyROOT/python/ROOT/pythonization/_rvec.py b/bindings/pyroot_experimental/PyROOT/python/ROOT/pythonization/_rvec.py
index 612c33370bb..aa1c6ac6ca5 100644
--- a/bindings/pyroot_experimental/PyROOT/python/ROOT/pythonization/_rvec.py
+++ b/bindings/pyroot_experimental/PyROOT/python/ROOT/pythonization/_rvec.py
@@ -33,7 +33,9 @@ def get_array_interface(self):
             dtype_size = GetSizeOfType(dtype)
             endianess = GetEndianess()
             size = self.size()
-            if self.empty(): # Numpy sees a null pointer as error even though the data is never accessed.
+            # Numpy breaks for data pointer of 0 even though the array is empty.
+            # We set the pointer to 1 but the value itself is arbitrary and never accessed.
+            if self.empty():
                 pointer = 1
             else:
                 pointer = GetVectorDataPointer(self, cppname)
-- 
GitLab