Skip to content

Unit conversion methods and their names #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
andrewgsavage opened this issue Apr 18, 2025 · 3 comments
Open

Unit conversion methods and their names #19

andrewgsavage opened this issue Apr 18, 2025 · 3 comments

Comments

@andrewgsavage
Copy link
Contributor

There's discussion starting #9 (comment) about unit conversion and the methods.

in short:
What should the name of a unit conversion function that returns a quantity be?
Potential names:

Should a unit conversion function that returns the value exist, and what should it be named?

  • The aforementioned function could be used, and then use Quantity.value, so this doesn't need to exist in the initial release.
    Potential names:
  • uconvert_value
  • convert_value is my suggestion

Should a general function exist for converting between units? ie convert(unit1, unit2, value)

@nstarman
Copy link
Contributor

nstarman commented Apr 20, 2025

My current thoughts:

  • asquantity: IMO its fine for the function to be flexible and call the official unit conversion function, like numpy.asarray can internally call numpy.astype for dtype conversion.
  • asunit 👎
  • convert 👎 Explicit is better than implicit. We're doing unit conversion, this name is for any conversion.
  • uconvert 👍. Explicit is better than implicit. Readability counts.
  • convert_quantity 🤷 it's ambiguous IMO. What on quantities are we converting — the class type, the unit, the dtype? This name works equally well for inter-library quantity type conversion, unit conversion, and dtype conversion. Yes the context of other functions is important, but also each function name should stand on its own.
  • convert_unit_on_quantity: 👎 0 ambiguity, but not concise. Straw man counterexample to all the concise names above 😆

Should a unit conversion function that returns the value exist, and what should it be named?

Yes.
The same thoughts about name ambiguity apply.

@andrewgsavage
Copy link
Contributor Author

andrewgsavage commented Apr 20, 2025

  • uconvert 👍. Explicit is better than implicit. Readability counts.

so make it units_convert!

@nstarman
Copy link
Contributor

nstarman commented Apr 20, 2025

Then does it convert unit (e.g. km to kpc) or units on quantity?
Funnily enough this is similar to uconvert, however the fact that it's "more" explicit also makes it more ambiguous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants