mcgibbon / sympl

A toolkit for building planetary/Earth system models in Python
http://sympl.readthedocs.io
Other
50 stars 14 forks source link

DataArray.value shortcut to DataArray.values.item() #15

Closed mcgibbon closed 6 years ago

mcgibbon commented 6 years ago

It would be nice to have a shorthand for DataArray.values.item() since it gets used so often for constants. Let's make it so that sympl.DataArray.value is the scalar contained inside the DataArray (as opposed to sympl.DataArray.values which is a numpy array scalar).

On the other hand, maybe we should just be using numpy array scalars? Is there anything wrong with just using .values? Are there cases where we actually need the .item()?

JoyMonteiro commented 6 years ago

I removed .item() from all my code, and no tests break. So, it seems as if it is not really necessary.

However, adding .value IMO makes the code more natural to read -- default_constants['boltzmann_constant'].value makes more sense than default_constants['boltzmann_constant'].values

mcgibbon commented 6 years ago

Even if it's more natural to read .value, it's more confusing to have both. Most people who have already used xarray (or are going to) are used to .values. I think for now I'll leave it as is, and stop using .item() in my own code.

JoyMonteiro commented 6 years ago

alright, I think we could revisit this if necessary at a later time.