Skip to content

Importing pyresample without having Xarray and/or zarray raises UserWarning #375

@geoffrey464

Description

@geoffrey464

Code Sample, a minimal, complete, and verifiable piece of code

import pyresample
test_resample_import.py:10: UserWarning: XArray and/or zarr not found, XArrayBilinearResampler won't be available.
  warnings.warn("XArray and/or zarr not found, XArrayBilinearResampler won't be available.")

Problem description

When importing pyresample without having XArray installed the above warning is thrown. I consciously have not installed XArray with this package since it is not on a major version yet. However this means that every time I run the pyresample import for my code I see this warning at the top of the stdout. If pyresample requires XArray to be importable should Xarray be included as a dependency (I noticed that it is included on the "xarray_bilinear" extras)?

A possible solution to this without requiring XArray as a dependency would be to include the ImportWarning category on the try/except block in the pyresample/bilinear/init.py file.

    warnings.warn("XArray and/or zarr not found, XArrayBilinearResampler won't be available.", category=ImportWarning)

This would still log the warning but only display it in Python Development Mode.

I think that there should be error handling when the user tries to use the XArrayBilinearResampler without having Xarray installed, but not on the import of the package. Since it is still unknown at import if the user will be using XArrayBilinearResampler or just NumpyBilinearResampler.

I currently have a hotfix by surrounding the import statment with a catch_warnings() block,

with warnings.catch_warnings():
    warnings.simplefilter('ignore', UserWarning)
    import pyresample

Versions of Python, package at hand and relevant dependencies

I am currently testing this on python 3.8 with the current base requirements: setuptools>=3.2', 'pyproj>=2.2', 'configobj','pykdtree>=1.3.1', 'pyyaml', 'numpy>=1.10.0',

Thanks for your consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions