DocOtak / gsw-xarray

Wrapper for gsw that will add CF attributes to xarray.DataArray outputs
https://gsw-xarray.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
23 stars 3 forks source link

Trying another backend #22

Closed rcaneill closed 2 years ago

rcaneill commented 2 years ago

I had another idea on how to deal with the functions names and their relative attributes using a dictionary. What do you think of this idea? This PR is not meant to be merged, but just to present this idea. If you agree, I'll implement it on PR #20 along with all units. Linked to #21

DocOtak commented 2 years ago

I don't think there is any good way around having a bunch of data somehow and having a dict of attrs (and xr.DataArray.name?) is probably "good enough" also the PEP 20 adage "explicit is better than implicit" probably applies, that is, a tuple could be confusing unless we use something like a NamedTuple

Would it be a good idea to control the unit values somehow? e.g. via enum:

>>> from enum import Enum
>>> class Units(Enum):
...   degC = "deg C"
...   gkg = "g kg-1"
... 
>>> Units.degC
<Units.degC: 'deg C'>
>>> Units.degC.value
'deg C'

I'm only thinking ways to ensure consistency, these could also be checked in tests against a short list of allowed unit values. At some point we might want to test compatibility with things like pint, which has slightly different parsing than the CF UDUNITS2. If unit changes are needed I'd want some way to ensure that everything is consistent.

Lets proceed with this draft PRs way of organizing data. Lets do it in two steps (separate PR/change sets):

We should probably do a 0.2.0 release soon after :)

rcaneill commented 2 years ago
  • Change the way it works internally for existing wrapped functions

I will work on this when we will have resolved #26

rcaneill commented 2 years ago

Implemented correctly in PR #27