Commit 0c1b4673 authored by Klaus Wölfel's avatar Klaus Wölfel

Option to redefine column names in data array

parent 0da07b5f
......@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import numpy as np
from Products.ERP5Type.Base import TempBase
from erp5.component.document.DataArray import DataArray
from Products.ERP5Type.Utils import createExpressionContext, \
......@@ -51,14 +52,26 @@ class DataArrayLine(DataArray):
Get numpy view of Parent Data Array according to index.
"""
getindex = GetIndex("getindex")
expression_context = createExpressionContext(None, portal=getindex)
index = evaluateExpressionFromString(
expression_context,
createExpressionContext(None, portal=getindex),
"python: portal[%s]" %self.getIndexExpression()
)
array_view = self.getParentValue().getArray()[index]
dtype = self.getDtype()
if dtype is not None:
zbigarray = self.getParentValue().getArray()
try:
array_view = zbigarray[index]
except TypeError:
array = zbigarray[:]
new_dtype = np.dtype({name:array.dtype.fields[name] for name in index})
array_view = np.ndarray(array.shape, new_dtype, array, 0, array.strides)
name_list = self.getNameList()
dtype_expression = self.getDtypeExpression()
if dtype_expression is not None or name_list:
if dtype_expression is None:
dtype = np.dtype(array_view.dtype)
else:
dtype = evaluateExpressionFromString(
createExpressionContext(None, portal=getindex),
dtype_expression)
dtype.names = name_list
return array_view.view(dtype=dtype)
else:
return array_view
return array_view
......@@ -22,7 +22,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>dtype_property</string> </value>
<value> <string>dtype_expression_property</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/lines</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>List of filends name of array dtype</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>name_property</string> </value>
</item>
<item>
<key> <string>multivalued</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -75,7 +75,6 @@
<value>
<list>
<string>my_reference</string>
<string>my_dtype</string>
</list>
</value>
</item>
......@@ -84,6 +83,8 @@
<value>
<list>
<string>my_index_expression</string>
<string>my_dtype_expression</string>
<string>my_name_list</string>
</list>
</value>
</item>
......
......@@ -17,7 +17,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_dtype</string> </value>
<value> <string>my_dtype_expression</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
......@@ -78,7 +78,7 @@
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
<value> <string>my_view_mode_tales_expression</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment