From 699f9610c25101b8c98ba2d289852621067c56cf Mon Sep 17 00:00:00 2001 From: Jussi Tiira Date: Fri, 8 Nov 2024 18:41:04 +0200 Subject: [PATCH] FIX: Ensure backwards compatibility with datatree/new versions of xarray (#1681) * try to use datatree from xarray * FIX: Fix some small linting errors * FIX: Fix the import of register datatree accessor * DEP: Update dependencies to work with newer versions of xarray/xradar * FIX: Update CI to only run for 3.10+ * FIX: Fix bad version in requirements --------- Co-authored-by: Max Grover Co-authored-by: mgrover1 --- .github/workflows/ci.yml | 2 +- continuous_integration/environment-ci.yml | 4 ++-- doc/environment.yml | 4 ++-- pyart/xradar/accessor.py | 20 ++++++++++++++++---- requirements.txt | 4 ++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35510155b1..c86bfe1522 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] os: [macos, ubuntu, windows] steps: diff --git a/continuous_integration/environment-ci.yml b/continuous_integration/environment-ci.yml index 8b0c4a171c..7246e5540d 100644 --- a/continuous_integration/environment-ci.yml +++ b/continuous_integration/environment-ci.yml @@ -12,7 +12,7 @@ dependencies: - wradlib - cartopy - cvxopt - - xarray<=2024.9.0 + - xarray>=2024.10.0 - metpy - pytest-cov - pytest-mpl @@ -25,7 +25,7 @@ dependencies: - shapely - ruff - mda-xdrlib - - xradar<=0.7.0 + - xradar>=0.8.0 - pooch - versioneer - black diff --git a/doc/environment.yml b/doc/environment.yml index a113afdb22..15d21df637 100644 --- a/doc/environment.yml +++ b/doc/environment.yml @@ -13,7 +13,7 @@ dependencies: - metpy - cartopy - cvxopt - - xarray<=2024.9.0 + - xarray>=2024.10.0 - sphinx<7.2 - ipython - pandoc @@ -34,7 +34,7 @@ dependencies: - pre_commit - cmweather - mda-xdrlib - - xradar<=0.7.0 + - xradar>=0.8.0 - dask - pip - pip: diff --git a/pyart/xradar/accessor.py b/pyart/xradar/accessor.py index 50c17edce2..b9efd7ea63 100644 --- a/pyart/xradar/accessor.py +++ b/pyart/xradar/accessor.py @@ -5,11 +5,23 @@ import copy -import datatree import numpy as np import pandas as pd -from datatree import DataTree, formatting, formatting_html -from datatree.treenode import NodePath + +try: + from xarray.core import formatting, formatting_html + from xarray.core.datatree import DataTree + from xarray.core.extensions import register_datatree_accessor + from xarray.core.treenode import NodePath +except ImportError: + from datatree import ( + DataTree, + formatting, + formatting_html, + ) + from datatree.extensions import register_datatree_accessor + from datatree.treenode import NodePath + from xarray import DataArray, Dataset, concat from xarray.core import utils from xradar.accessors import XradarAccessor @@ -807,7 +819,7 @@ def _point_altitude_data(): return _point_altitude_data -@datatree.register_datatree_accessor("pyart") +@register_datatree_accessor("pyart") class XradarDataTreeAccessor(XradarAccessor): """Adds a number of pyart specific methods to datatree.DataTree objects.""" diff --git a/requirements.txt b/requirements.txt index 52c9a3b514..423558aaf1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,9 +7,9 @@ cftime fsspec s3fs open_radar_data -xradar<=0.7.0 +xradar>=0.8.0 pandas mda-xdrlib -xarray<=2024.9.0 +xarray>=2024.10.0 cartopy pint