Test for Null & Empty Data

Hi All,

So in my data tree there is empty and null branch. How can I script in a way that test for null/ empty, if true grab the nearest data above them?

1 Like

You can use the NullRep (“Replace Nulls”) component to substitute null values with other data.

2 Likes

Usually the clean tree component works well.

I had a problem involving this the other day where I had to measure the length of the text and input that into If(x>0,True,False) in an expression block, then cull the list based on that pattern.

What about this?:

in native:

2 Likes

Or even simplier:

for(int i = 1; i < x.Count; i++)
{
  if(x[i] == "" || x[i] == null){
    x[i] = x[i-1];
  }
}
A = x;

which is exactly what @Baris done without scripting.

1 Like

Thanks @Lukas_Mateja . Did it for GH Python

That is mostly correct. just be aware that 1st item is problematic because you’re telling it to take one before Python is smart so it will take last item instead (which btw could be empty too).

That’s why I excluded 1st element from cycle. Even better would be to write special test for 1st item and decide what to do with it in case it is empty. I decided to replace it with first not empty/null element after it.

3 Likes

@Lukas_Mateja Cheers mate, you are a legend. Will keep that in mind.