Skip to content

Should Imperial units be imported by default? - #1073

Closed
mdboom wants to merge 2 commits into
astropy:masterfrom
mdboom:unit/hide-imperial
Closed

mdboom wants to merge 2 commits into
astropy:masterfrom
mdboom:unit/hide-imperial

Conversation

@mdboom

@mdboom mdboom commented May 8, 2013

Copy link
Copy Markdown
Contributor

Currently we include a hodge-podge of U. S. imperial units in the default set of units.

Since these are not terribly useful for science or astronomy, and British imperial units which are likely to name clash with these, should we perhaps not include them by default, but instead require the user to

from astropy.units import imperial

to access them?

@astrofrog

Copy link
Copy Markdown
Member

I can't think of a valid reason to have imperial units available by default for science. Though does it mean that e.g. u.inch won't be available?

@mdboom

mdboom commented May 7, 2013

Copy link
Copy Markdown
Contributor Author

It would mean u.inch wouldn't be available until doing from astropy.units import imperial. However, we could of course include inch as a one-off at the top-level if it's useful to have.

@hamogu

hamogu commented May 8, 2013

Copy link
Copy Markdown
Member

+1 for not including imperial units by default.

@eteq

eteq commented May 9, 2013

Copy link
Copy Markdown
Member

👍 to this, but can you add a prominent explanation how to bring them in somewhere close to the top of the units documentation page?

I totally agree this isn't usually useful for science, but occasionally one wants to do these conversions, and I have a feeling most users wouldn't realize this is here without having it prominently pointed out.

@astrofrog

Copy link
Copy Markdown
Member

I wonder whether we want to have to require the user to import imperial, or whether we want a function/method-based way of doing it, e.g.

u.enable('imperial')

otherwise it's not clear to the user that importing a module will add new attributes to u.

@taldcroft

Copy link
Copy Markdown
Member

+1 on some function-based approach. I saw the from astropy.units import imperial and immediately wondered "OK, so how do use the imperial units now?". Or might this be a ConfigurationItem?

@astrofrog

Copy link
Copy Markdown
Member

I would say -1 to ConfigurationItem, because people might then write code that will work on one machine but not another depending on the local settings.

@mdboom

mdboom commented May 10, 2013

Copy link
Copy Markdown
Contributor Author

If we do take the u.enable approach, I would say that we also refactor all of the modules that define units so that everything happens inside a function -- i.e. importing doesn't define units. Maybe importing just causes it to register itself in the table that u.enable would use to enable units. Otherwise, we'll have MTOWTDI.

@mdboom

mdboom commented May 10, 2013

Copy link
Copy Markdown
Contributor Author

Also -- as suggested elsewhere, we should probably rename this from imperial or separate out the truly imperial from other units. Might as well do this as part of this PR.

@mdboom

mdboom commented May 13, 2013

Copy link
Copy Markdown
Contributor Author

I think the ultimate solution to this is probably to have a list of namespaces that are searched for things -- that will make it easier to add and later remove categories of units. I don't know if that needs to hold up this PR, though, which I think is a step forward in any case.

@eteq: In the part of the units documentation where the defined units are listed, it now includes an explanation about the fact that the imperial units are not included by default and how to get them. Is that sufficient? It seems like the right place to include this information. I'll also add this to some of the basic examples, which will put it front-and-center.

Comment thread docs/units/index.rst

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect a fair number of people will only see this part, so it might be worth beefing it up just a bit with something like:

# Imperial units are not included when you import units 
# but will be added if you import the `imperial` module

Or something like that.

@eteq

eteq commented May 13, 2013

Copy link
Copy Markdown
Member

Yep, it seems fine to me other than the minor suggestion above.

There's also one test that is now failing. I think you just need to add the radioactivity units to the list in test_equivalent_units2, and perhaps a from from ... import units.imperial in that function just to make sure the imperials have been imported.

This does raise a minor concern that now the tests are somewhat non-deterministic, given that an import changes the package's state (order of tests is not necessarily guaranteed, I believe). Not a big deal to me, but perhaps worth noting at the top of the test file or something in case someone else gets tripped up by it.

@mdboom

mdboom commented May 16, 2013

Copy link
Copy Markdown
Contributor Author

I think I'm just going to put this off as it is now and rethink this in the context of how we want to handle optional namespaces of units in general.

@mdboom

mdboom commented Aug 12, 2013

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1268.

@mdboom mdboom closed this Sep 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants