Refactor semantic constants to enumerations
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 150
- Forks
- 23
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 2
Description
In code review at https://github.com/NCAS-CMS/cf-python/pull/910#discussion_r2975606868 I noted that we could replace a tuple defining valid indexing schemes with an equivalent enumeration:
We agreed we should at some point survey the codebase systematically for further appropriate places to use enumerations to e.g. make comparisons against well-defined sets of values such as controlled vocabs more robust, clear and type safe.
We already have Enums applied well for a few cases:
From a quick look, some further good candidates across the codebase for using these are:
- Also in the
constantsmodule as above: the CF cell methods set, and perhaps the keys from thecr_coordinatesdict and the formula coordinate types (atmosphere_sigma_coordinate,ocean_s_coordinate,ocean_sigma_z_coordinate, etc.) both of which appear across multiple dictionaries there (which could in turn be converted to data classes, also an improvement); - The valid regridding methods, i.e. keys to:
https://github.com/NCAS-CMS/cf-python/blob/02e348c5c84784e6a1613c3722a3c2ed1a0fd25d/cf/regrid/regrid.py#L20-L29 - (Upstream in
cfdm*) the valid backends for reading and writing: https://github.com/NCAS-CMS/cfdm/blob/e6ebddb4a0f533f079f7f1ea0da2efdf6595c928/cfdm/read_write/netcdf/netcdfread.py#L1334-L1339 (for netCDF only) and https://github.com/NCAS-CMS/cfdm/blob/e6ebddb4a0f533f079f7f1ea0da2efdf6595c928/cfdm/read_write/netcdf/netcdfwrite.py#L5768 respectively.
* we should consider for all Enums defined whether it is best to define and import them in from cfdm, or have them in cf-python only.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the tuple in cf/functions.py, the existing Enum definitions in cf/constants.py, and the valid regridding methods in cf/regrid/regrid.py. Survey the listed constants and repeated controlled-value sets, then determine a focused scope and whether definitions belong in cf-python or cfdm. Done means the agreed semantic constants use appropriate enumerations without breaking existing comparisons or interfaces.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100