Skip to content

xarrayprovider gen_covjson fails with nan data #2348

@dschneider-wxs

Description

@dschneider-wxs

Description
I am using the XarrayProvider and XarrayEDRProvider with a netcdf file and the XarrayProvider.gen_covjson() seems to be tripping over itself. If the dataset has missing values as NaN, they are converted to None and then fail during serialization because np.isnan on None raises a TypeError.

starting at Line 400 pygeoapi/provider/xarray_.py

        data = data.fillna(None)

        try:
            for key, value in selected_fields.items():
                LOGGER.debug(f'Adding range {key}')
                range = {
                    'type': 'NdArray',
                    'dataType': value['type'],
                    'axisNames': [
                        'y', 'x'
                    ],
                    'shape': [
                        metadata['height'], metadata['width']
                    ],
                    'values': [
                        None if np.isnan(v) else v
                        for v in data[key].values.flatten()
                    ]
                }

I don't think I understand the point of setting None here if the code is checking for nan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions