cf-xarray 0.9.4__tar.gz → 0.9.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/workflows/ci.yaml +2 -2
  2. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.pre-commit-config.yaml +7 -7
  3. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.readthedocs.yml +3 -2
  4. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/PKG-INFO +2 -3
  5. cf_xarray-0.9.5/cf_xarray/_version.py +1 -0
  6. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/accessor.py +8 -2
  7. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/geometry.py +36 -31
  8. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_accessor.py +3 -1
  9. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_geometry.py +1 -1
  10. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray.egg-info/PKG-INFO +2 -3
  11. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/ci/doc.yml +2 -2
  12. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/pyproject.toml +1 -2
  13. cf_xarray-0.9.4/cf_xarray/_version.py +0 -1
  14. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.binder/environment.yml +0 -0
  15. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.deepsource.toml +0 -0
  16. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/dependabot.yml +0 -0
  17. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/release.yml +0 -0
  18. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/workflows/parse_logs.py +0 -0
  19. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/workflows/pypi.yaml +0 -0
  20. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/workflows/testpypi-release.yaml +0 -0
  21. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.github/workflows/upstream-dev-ci.yaml +0 -0
  22. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.gitignore +0 -0
  23. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/.tributors +0 -0
  24. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/CITATION.cff +0 -0
  25. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/LICENSE +0 -0
  26. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/README.rst +0 -0
  27. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/__init__.py +0 -0
  28. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/coding.py +0 -0
  29. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/criteria.py +0 -0
  30. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/datasets.py +0 -0
  31. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/formatting.py +0 -0
  32. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/helpers.py +0 -0
  33. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/options.py +0 -0
  34. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/py.typed +0 -0
  35. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/scripts/make_doc.py +0 -0
  36. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/scripts/print_versions.py +0 -0
  37. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/sgrid.py +0 -0
  38. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/__init__.py +0 -0
  39. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/conftest.py +0 -0
  40. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_coding.py +0 -0
  41. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_helpers.py +0 -0
  42. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_options.py +0 -0
  43. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_scripts.py +0 -0
  44. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/tests/test_units.py +0 -0
  45. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/units.py +0 -0
  46. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray/utils.py +0 -0
  47. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray.egg-info/SOURCES.txt +0 -0
  48. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray.egg-info/dependency_links.txt +0 -0
  49. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray.egg-info/requires.txt +0 -0
  50. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/cf_xarray.egg-info/top_level.txt +0 -0
  51. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/ci/environment-no-optional-deps.yml +0 -0
  52. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/ci/environment.yml +0 -0
  53. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/ci/upstream-dev-env.yml +0 -0
  54. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/codecov.yml +0 -0
  55. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/2D_bounds_averaged.png +0 -0
  56. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/2D_bounds_error.png +0 -0
  57. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/2D_bounds_nonunique.png +0 -0
  58. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/Makefile +0 -0
  59. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/dataset-diagram-logo.tex +0 -0
  60. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/full-logo.png +0 -0
  61. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/logo.png +0 -0
  62. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/logo.svg +0 -0
  63. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/rich-repr-example.png +0 -0
  64. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/_static/style.css +0 -0
  65. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/api.rst +0 -0
  66. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/bounds.md +0 -0
  67. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/cartopy_rotated_pole.png +0 -0
  68. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/coding.md +0 -0
  69. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/conf.py +0 -0
  70. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/contributing.rst +0 -0
  71. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/coord_axes.md +0 -0
  72. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/custom-criteria.md +0 -0
  73. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/dsg.md +0 -0
  74. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/examples/introduction.ipynb +0 -0
  75. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/faq.md +0 -0
  76. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/flags.md +0 -0
  77. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/geometry.md +0 -0
  78. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/grid_mappings.md +0 -0
  79. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/howtouse.md +0 -0
  80. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/index.rst +0 -0
  81. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/make.bat +0 -0
  82. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/parametricz.md +0 -0
  83. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/plotting.md +0 -0
  84. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/provenance.md +0 -0
  85. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/quickstart.md +0 -0
  86. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/roadmap.rst +0 -0
  87. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/selecting.md +0 -0
  88. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/sgrid_ugrid.md +0 -0
  89. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/units.md +0 -0
  90. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/doc/whats-new.rst +0 -0
  91. {cf_xarray-0.9.4 → cf_xarray-0.9.5}/setup.cfg +0 -0
@@ -27,7 +27,7 @@ jobs:
27
27
  fail-fast: false
28
28
  matrix:
29
29
  os: ["ubuntu-latest"]
30
- python-version: ["3.9", "3.12"]
30
+ python-version: ["3.10", "3.12"]
31
31
  steps:
32
32
  - uses: actions/checkout@v4
33
33
  with:
@@ -91,7 +91,7 @@ jobs:
91
91
  shell: bash -l {0}
92
92
  strategy:
93
93
  matrix:
94
- python-version: ["3.9", "3.12"]
94
+ python-version: ["3.10", "3.12"]
95
95
  steps:
96
96
  - uses: actions/checkout@v4
97
97
  with:
@@ -3,25 +3,25 @@ ci:
3
3
 
4
4
  repos:
5
5
  - repo: https://github.com/asottile/pyupgrade
6
- rev: v3.16.0
6
+ rev: v3.17.0
7
7
  hooks:
8
8
  - id: pyupgrade
9
- args: ["--py39-plus"]
9
+ args: ["--py310-plus"]
10
10
 
11
11
  - repo: https://github.com/astral-sh/ruff-pre-commit
12
12
  # Ruff version.
13
- rev: 'v0.5.0'
13
+ rev: 'v0.6.1'
14
14
  hooks:
15
15
  - id: ruff
16
16
  args: ["--show-fixes", "--fix"]
17
17
 
18
18
  - repo: https://github.com/psf/black-pre-commit-mirror
19
- rev: 24.4.2
19
+ rev: 24.8.0
20
20
  hooks:
21
21
  - id: black
22
22
 
23
23
  - repo: https://github.com/rstcheck/rstcheck
24
- rev: v6.2.0
24
+ rev: v6.2.4
25
25
  hooks:
26
26
  - id: rstcheck
27
27
  additional_dependencies: [sphinx, tomli]
@@ -36,7 +36,7 @@ repos:
36
36
  - mdformat-myst
37
37
 
38
38
  - repo: https://github.com/nbQA-dev/nbQA
39
- rev: 1.8.5
39
+ rev: 1.8.7
40
40
  hooks:
41
41
  - id: nbqa-black
42
42
  - id: nbqa-ruff
@@ -67,7 +67,7 @@ repos:
67
67
  - id: validate-cff
68
68
 
69
69
  - repo: https://github.com/abravalheri/validate-pyproject
70
- rev: v0.18
70
+ rev: v0.19
71
71
  hooks:
72
72
  - id: validate-pyproject
73
73
 
@@ -1,15 +1,16 @@
1
1
  version: 2
2
2
 
3
3
  build:
4
- os: ubuntu-22.04
4
+ os: ubuntu-lts-latest
5
5
  tools:
6
- python: mambaforge-4.10
6
+ python: mambaforge-latest
7
7
  jobs:
8
8
  post_checkout:
9
9
  - (git --no-pager log --pretty="tformat:%s" -1 | grep -vqF "[skip-rtd]") || exit 183
10
10
  pre_install:
11
11
  - conda list sphinx
12
12
  - conda list cf_xarray
13
+ - conda list
13
14
 
14
15
  conda:
15
16
  environment: ci/doc.yml
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cf_xarray
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: A convenience wrapper for using CF attributes on xarray objects
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -214,11 +214,10 @@ Classifier: License :: OSI Approved :: Apache Software License
214
214
  Classifier: Natural Language :: English
215
215
  Classifier: Operating System :: OS Independent
216
216
  Classifier: Programming Language :: Python
217
- Classifier: Programming Language :: Python :: 3.9
218
217
  Classifier: Programming Language :: Python :: 3.10
219
218
  Classifier: Programming Language :: Python :: 3.11
220
219
  Classifier: Programming Language :: Python :: 3.12
221
- Requires-Python: >=3.9
220
+ Requires-Python: >=3.10
222
221
  Description-Content-Type: text/x-rst
223
222
  License-File: LICENSE
224
223
  Requires-Dist: xarray
@@ -0,0 +1 @@
1
+ __version__ = "0.9.5"
@@ -5,11 +5,17 @@ import inspect
5
5
  import itertools
6
6
  import re
7
7
  from collections import ChainMap, namedtuple
8
- from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence
8
+ from collections.abc import (
9
+ Callable,
10
+ Hashable,
11
+ Iterable,
12
+ Mapping,
13
+ MutableMapping,
14
+ Sequence,
15
+ )
9
16
  from datetime import datetime
10
17
  from typing import (
11
18
  Any,
12
- Callable,
13
19
  Literal,
14
20
  TypeVar,
15
21
  Union,
@@ -459,11 +459,8 @@ def shapely_to_cf(
459
459
  "and set the grid mapping variable as a coordinate",
460
460
  )
461
461
 
462
- # Get all types to call the appropriate translation function.
463
- types = {
464
- geom.item().geom_type if isinstance(geom, xr.DataArray) else geom.geom_type
465
- for geom in geometries
466
- }
462
+ as_data = geometries.data if isinstance(geometries, xr.DataArray) else geometries
463
+ type_ = as_data[0].geom_type
467
464
 
468
465
  grid_mapping_varname = None
469
466
  if (
@@ -482,16 +479,21 @@ def shapely_to_cf(
482
479
  suffix=suffix, grid_mapping_name=grid_mapping, grid_mapping=grid_mapping_varname
483
480
  )
484
481
 
485
- if types.issubset({"Point", "MultiPoint"}):
486
- ds = points_to_cf(geometries, names=names)
487
- elif types.issubset({"LineString", "MultiLineString"}):
488
- ds = lines_to_cf(geometries, names=names)
489
- elif types.issubset({"Polygon", "MultiPolygon"}):
490
- ds = polygons_to_cf(geometries, names=names)
491
- else:
482
+ try:
483
+ if type_ in ["Point", "MultiPoint"]:
484
+ ds = points_to_cf(geometries, names=names)
485
+ elif type_ in ["LineString", "MultiLineString"]:
486
+ ds = lines_to_cf(geometries, names=names)
487
+ elif type_ in ["Polygon", "MultiPolygon"]:
488
+ ds = polygons_to_cf(geometries, names=names)
489
+ else:
490
+ raise ValueError(
491
+ f"This geometry type is not supported in CF-compliant datasets. Got {type_}"
492
+ )
493
+ except NotImplementedError as e:
492
494
  raise ValueError(
493
- f"Mixed geometry types are not supported in CF-compliant datasets. Got {types}"
494
- )
495
+ "Error converting geometries. Possibly you have provided mixed geometry types."
496
+ ) from e
495
497
 
496
498
  return ds
497
499
 
@@ -841,7 +843,7 @@ def polygons_to_cf(
841
843
  node_count = part_node_count
842
844
  elif len(offsets) >= 2:
843
845
  indices = np.take(offsets[0], offsets[1])
844
- interior_ring = np.isin(offsets[0], indices, invert=True)[:-1].astype(int)
846
+ interior_ring = np.isin(offsets[0], indices, invert=True)[:-1]
845
847
 
846
848
  if len(offsets) == 3:
847
849
  indices = np.take(indices, offsets[2])
@@ -852,29 +854,32 @@ def polygons_to_cf(
852
854
  crdX = geom_coords[:, 0]
853
855
  crdY = geom_coords[:, 1]
854
856
 
857
+ data_vars = {names.node_count: (dim, node_count)}
858
+ geometry_attrs = names.geometry_container_attrs
859
+
860
+ # Special case when we have no MultiPolygons and no holes
861
+ if len(part_node_count) != len(node_count):
862
+ data_vars[names.part_node_count] = (names.part_dim, part_node_count)
863
+ geometry_attrs["part_node_count"] = names.part_node_count
864
+
865
+ # Special case when we have no holes
866
+ if interior_ring.any():
867
+ data_vars[names.interior_ring] = (names.part_dim, interior_ring)
868
+ geometry_attrs["interior_ring"] = names.interior_ring
869
+
870
+ data_vars[names.container_name] = ( # type: ignore[assignment]
871
+ (),
872
+ np.nan,
873
+ {"geometry_type": "polygon", **geometry_attrs},
874
+ )
855
875
  ds = xr.Dataset(
856
- data_vars={
857
- names.node_count: xr.DataArray(node_count, dims=(dim,)),
858
- names.container_name: xr.DataArray(
859
- data=np.nan,
860
- attrs={"geometry_type": "polygon", **names.geometry_container_attrs},
861
- ),
862
- },
876
+ data_vars=data_vars,
863
877
  coords=names.coords(x=x, y=y, crdX=crdX, crdY=crdY, dim=dim),
864
878
  )
865
879
 
866
880
  if coord is not None:
867
881
  ds = ds.assign_coords({dim: coord})
868
882
 
869
- # Special case when we have no MultiPolygons and no holes
870
- if len(part_node_count) != len(node_count):
871
- ds[names.part_node_count] = xr.DataArray(part_node_count, dims=names.part_dim)
872
- ds[names.container_name].attrs["part_node_count"] = names.part_node_count
873
-
874
- # Special case when we have no holes
875
- if (interior_ring != 0).any():
876
- ds[names.interior_ring] = xr.DataArray(interior_ring, dims=names.part_dim)
877
- ds[names.container_name].attrs["interior_ring"] = names.interior_ring
878
883
  return ds
879
884
 
880
885
 
@@ -57,6 +57,8 @@ datasets = [airds, airds.chunk({"lat": 5})]
57
57
  dataarrays = [airds.air, airds.air.chunk({"lat": 5})]
58
58
  objects = datasets + dataarrays
59
59
 
60
+ xr.set_options(use_flox=False)
61
+
60
62
 
61
63
  def assert_dicts_identical(dict1, dict2):
62
64
  assert dict1.keys() == dict2.keys()
@@ -1125,7 +1127,7 @@ def _check_unchanged(old, new):
1125
1127
  else:
1126
1128
  assert v == n[k]
1127
1129
 
1128
- assert type(old) == type(new)
1130
+ assert type(old) == type(new) # noqa
1129
1131
  _check_attrs_equal(old.attrs, new.attrs)
1130
1132
 
1131
1133
  # Check coordinate attributes and data variable attributes
@@ -352,7 +352,7 @@ def test_shapely_to_cf_errors():
352
352
  Polygon([[1, 1, 4], [1, 3, 4], [3, 3, 3], [1, 1, 4]]),
353
353
  Point(1, 2),
354
354
  ]
355
- with pytest.raises(ValueError, match="Mixed geometry types are not supported"):
355
+ with pytest.raises(ValueError, match="Geometry type combination"):
356
356
  cfxr.shapely_to_cf(geoms)
357
357
 
358
358
  encoded = cfxr.shapely_to_cf(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cf_xarray
3
- Version: 0.9.4
3
+ Version: 0.9.5
4
4
  Summary: A convenience wrapper for using CF attributes on xarray objects
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -214,11 +214,10 @@ Classifier: License :: OSI Approved :: Apache Software License
214
214
  Classifier: Natural Language :: English
215
215
  Classifier: Operating System :: OS Independent
216
216
  Classifier: Programming Language :: Python
217
- Classifier: Programming Language :: Python :: 3.9
218
217
  Classifier: Programming Language :: Python :: 3.10
219
218
  Classifier: Programming Language :: Python :: 3.11
220
219
  Classifier: Programming Language :: Python :: 3.12
221
- Requires-Python: >=3.9
220
+ Requires-Python: >=3.10
222
221
  Description-Content-Type: text/x-rst
223
222
  License-File: LICENSE
224
223
  Requires-Dist: xarray
@@ -3,7 +3,7 @@ channels:
3
3
  - conda-forge
4
4
  dependencies:
5
5
  - pip
6
- - python=3.10
6
+ - python
7
7
  - matplotlib-base
8
8
  - netcdf4
9
9
  - pooch
@@ -20,7 +20,7 @@ dependencies:
20
20
  - pint
21
21
  - regex
22
22
  - shapely
23
- - furo
23
+ - furo>=2024
24
24
  - myst-nb
25
25
  - pip:
26
26
  - -e ../
@@ -2,7 +2,7 @@
2
2
  name = "cf_xarray"
3
3
  description = "A convenience wrapper for using CF attributes on xarray objects"
4
4
  readme = "README.rst"
5
- requires-python = ">=3.9"
5
+ requires-python = ">=3.10"
6
6
  license = {file = "LICENSE"}
7
7
  keywords = ["xarray", "metadata", "CF conventions"]
8
8
  classifiers = [
@@ -11,7 +11,6 @@ classifiers = [
11
11
  "Natural Language :: English",
12
12
  "Operating System :: OS Independent",
13
13
  "Programming Language :: Python",
14
- "Programming Language :: Python :: 3.9",
15
14
  "Programming Language :: Python :: 3.10",
16
15
  "Programming Language :: Python :: 3.11",
17
16
  "Programming Language :: Python :: 3.12",
@@ -1 +0,0 @@
1
- __version__ = "0.9.4"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes