LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Change Null value into 0 (zero)

    Employee
    Posted 09-30-2013 07:16

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ouwen010

    When using the "Pivot - Data To Names" node the result contains Null values for some fields. I need to change these Null values into 0 (zero). How can I do this?


  • 2.  RE: Change Null value into 0 (zero)

    Employee
    Posted 10-15-2013 05:58

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: awilliams

    At the moment i've got two solutions for this.

    You can either use a filter node, emit the fields with .ifNull(0) on the affected fields. This works great if you're working with a small subset of static fields, but if the input is dynamic then it presents a problem.

    The second solution was a small Python node to look for numeric fields and set the value to zero in the instance where its null.

    node:Zero_Fields
    bretype:core::Python
    editor:Label=Zero Fields
    editor:sortkey=51cd2fdc1d4f628f
    input:51cd2fa77a717730/PivotedData=Calculate_Flow.51cd2dd1177116a2
    output:51cd303605e734c9/out1=
    prop:Python2Implementation=<<EOX
    import braininfo
    
    
    def setup(brainNodeControlObj, BrainNodeClass):
    
    
    	class BrainNode(BrainNodeClass):
    		def initialize(self):
    			super(BrainNode, self).initialize()			
    			self.keys = []
    			md = self.inputs[0].metadata
    			for k, t in md:
    				if t in ['int', 'long', 'bint', 'blong', 'double', 'bdouble']:
    					self.keys.append(k)
    
    
    		def finalize(self, val):
    			super(BrainNode, self).finalize(val)
    
    
    		def pump(self, quant):
    			while quant.permitsRunning(self):
    				rec = self.inputs[0].read()
    				if not rec: return False
    				for k in self.keys:
    					if rec[k] == None:
    						rec[k] = 0
    				self.outputs[0].write(rec)
    			return True  
    
    
    	return BrainNode
    EOX
    editor:XY=600,410
    end:Zero_Fields