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 @@ ...@@ -26,6 +26,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import numpy as np
from Products.ERP5Type.Base import TempBase from Products.ERP5Type.Base import TempBase
from erp5.component.document.DataArray import DataArray from erp5.component.document.DataArray import DataArray
from Products.ERP5Type.Utils import createExpressionContext, \ from Products.ERP5Type.Utils import createExpressionContext, \
...@@ -51,14 +52,26 @@ class DataArrayLine(DataArray): ...@@ -51,14 +52,26 @@ class DataArrayLine(DataArray):
Get numpy view of Parent Data Array according to index. Get numpy view of Parent Data Array according to index.
""" """
getindex = GetIndex("getindex") getindex = GetIndex("getindex")
expression_context = createExpressionContext(None, portal=getindex)
index = evaluateExpressionFromString( index = evaluateExpressionFromString(
expression_context, createExpressionContext(None, portal=getindex),
"python: portal[%s]" %self.getIndexExpression() "python: portal[%s]" %self.getIndexExpression()
) )
array_view = self.getParentValue().getArray()[index] zbigarray = self.getParentValue().getArray()
dtype = self.getDtype() try:
if dtype is not None: 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) return array_view.view(dtype=dtype)
else: return array_view
return array_view
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>dtype_property</string> </value> <value> <string>dtype_expression_property</string> </value>
</item> </item>
<item> <item>
<key> <string>portal_type</string> </key> <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 @@ ...@@ -75,7 +75,6 @@
<value> <value>
<list> <list>
<string>my_reference</string> <string>my_reference</string>
<string>my_dtype</string>
</list> </list>
</value> </value>
</item> </item>
...@@ -84,6 +83,8 @@ ...@@ -84,6 +83,8 @@
<value> <value>
<list> <list>
<string>my_index_expression</string> <string>my_index_expression</string>
<string>my_dtype_expression</string>
<string>my_name_list</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>my_dtype</string> </value> <value> <string>my_dtype_expression</string> </value>
</item> </item>
<item> <item>
<key> <string>message_values</string> </key> <key> <string>message_values</string> </key>
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
</item> </item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value> <value> <string>my_view_mode_tales_expression</string> </value>
</item> </item>
<item> <item>
<key> <string>form_id</string> </key> <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