# How to discard NaN value datasets using Python shell?

**URL:** https://discourse.paraview.org/t/how-to-discard-nan-value-datasets-using-python-shell/9658
**Category:** ParaView Support
**Created:** [May 22, 2022, 10:45pm UTC](https://discourse.paraview.org/t/how-to-discard-nan-value-datasets-using-python-shell/9658 "2022-05-22T22:45:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mario119](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mario119/32/9238_2.png) [@mario119](https://discourse.paraview.org/u/mario119)
#### Post date: [May 22, 2022, 10:45pm UTC](https://discourse.paraview.org/t/how-to-discard-nan-value-datasets-using-python-shell/9658/1 "2022-05-22T22:45:59Z")

</div>

I tried to interpolate my dataset but after interpolating it, some dataset resulted in NaN values.  
In order to discard the dataset, I need to make a ’ if ’ conditional part to save only real numbers.  
From the resulted spread sheet, the name of the column having NaN values is ‘pressure’.  
I thought I can write the code like this below, but it did not work at all…

```auto
# save data
if np.isnan(interp_model['pressure']) == False:
            SaveData(os.path.join(tar_dir_new, filename), proxy=interp_model, PointDataArrays=data_array)

```

My Python script for interpolation looks like this.

```auto
# Loop through different reduction rates
for rate in reduction_rates:
    print(f"reduction rate = {rate:.1f}")
    # Define target directory for each reduction rate
    tar_dir_new = os.path.join(tar_dir, f"reduction_rate={rate:.1f}")
    if not os.path.exists(tar_dir_new):
        os.makedirs(tar_dir_new)

    # Load target grid
    # Assumes reduced mesh is saved in ".vtk" format and that is the only ".vtk" file in the directory
    reduced_path = os.path.join(tar_dir_new, [n for n in os.listdir(tar_dir_new) if ".vtk" in n][0])
    reduced_model = LegacyVTKReader(
        registrationName=os.path.basename(reduced_path),
        FileNames=[reduced_path]
    )
    UpdatePipeline(time=0.0, proxy=reduced_model)

    # Loop through src directory
    for root, dirs, files in os.walk(src_dir):
        # Finds files ending with ".vtp" and assume they are original data
        file_to_look = [n for n in files if ".vtp" in n]
        for n, filename in enumerate(file_to_look):
            print(f"\t{n + 1} / {len(file_to_look)}: ")
            src_path = os.path.join(root, filename)

            # Read source file
            src_model = XMLPolyDataReader(
                registrationName=os.path.basename(src_path),
                FileName=[src_path]
            )
            src_model.PointArrayStatus = data_array
            src_model.TimeArray = 'None'
            UpdatePipeline(time=0.0, proxy=src_model)

            # create a new 'Point Dataset Interpolator'
            interp_model = PointDatasetInterpolator(
                registrationName='PointDatasetInterpolator1',
                Input=src_model,
                Source=reduced_model
            )
            interp_model.Kernel = 'VoronoiKernel'
            interp_model.Locator = 'Static Point Locator'
            UpdatePipeline(time=0.0, proxy=interp_model)

            # save data
            SaveData(os.path.join(tar_dir_new, filename), proxy=interp_model, PointDataArrays=data_array)

    ResetSession()

```

How can I skip saving interpolated dataset that has NaN values?

Thanks!
