{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/602","labels_url":"https://api.github.com/repos/astropy/astropy/issues/602/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/602/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/602/events","html_url":"https://github.com/astropy/astropy/pull/602","id":9649840,"number":602,"title":"Improve whitespace handling in astropy.unit.Unit FITS format string parsing?","user":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/astropy/astropy/milestones/2","html_url":"https://github.com/astropy/astropy/milestones/v0.2.0","labels_url":"https://api.github.com/repos/astropy/astropy/milestones/2/labels","id":128949,"number":2,"title":"v0.2.0","description":"","creator":{"login":"astrofrog","id":314716,"avatar_url":"https://avatars.githubusercontent.com/u/314716?v=3","gravatar_id":"","url":"https://api.github.com/users/astrofrog","html_url":"https://github.com/astrofrog","followers_url":"https://api.github.com/users/astrofrog/followers","following_url":"https://api.github.com/users/astrofrog/following{/other_user}","gists_url":"https://api.github.com/users/astrofrog/gists{/gist_id}","starred_url":"https://api.github.com/users/astrofrog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astrofrog/subscriptions","organizations_url":"https://api.github.com/users/astrofrog/orgs","repos_url":"https://api.github.com/users/astrofrog/repos","events_url":"https://api.github.com/users/astrofrog/events{/privacy}","received_events_url":"https://api.github.com/users/astrofrog/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":283,"state":"closed","created_at":"2012-06-06T22:05:39Z","updated_at":"2013-11-10T01:21:14Z","due_on":"2012-11-06T08:00:00Z","closed_at":"2013-02-20T13:28:11Z"},"comments":4,"created_at":"2013-01-03T17:28:30Z","updated_at":"2015-07-21T16:40:56Z","closed_at":"2013-01-04T15:48:35Z","pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/602","html_url":"https://github.com/astropy/astropy/pull/602","diff_url":"https://github.com/astropy/astropy/pull/602.diff","patch_url":"https://github.com/astropy/astropy/pull/602.patch"},"body":"I  ran into this error:\r\n\r\n```\r\nIn [81]: u.Unit('m / s')\r\nERROR: ValueError: Expected integer (at char 5) in 'm / s' [astropy.units.format.generic]\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-81-ee9c94fa4475> in <module>()\r\n----> 1 u.Unit('m / s')\r\n\r\n/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy/units/core.pyc in __call__(self, s, represents, format, register, doc, parse_strict)\r\n    735             f = unit_format.get_format(format)\r\n    736             try:\r\n--> 737                 return f.parse(s)\r\n    738             except ValueError as e:\r\n    739                 if parse_strict == 'raise':\r\n\r\n/Users/deil/Library/Python/2.7/lib/python/site-packages/astropy/units/format/generic.pyc in parse(self, s)\r\n    247             except p.ParseException as e:\r\n    248                 raise ValueError(\"{0} in {1!r}\".format(\r\n--> 249                     utils.cleanup_pyparsing_error(e), s))\r\n    250 \r\n    251     def _get_unit_name(self, unit):\r\n\r\nValueError: Expected integer (at char 5) in 'm / s'\r\n```\r\n\r\nIt took me a minute to figure out that the spaces are the problem, this works:\r\n```\r\nIn [82]: u.Unit('m/s')\r\nOut[82]: Unit(\"m / (s)\")\r\n```\r\n\r\nAfter reading Section 4.3.1 on \"Construction of units strings\" of the [FITS Standard](http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf) I realize that the spaces in the `'m / s'` unit string is discouraged and thus the behaviour of the astropy parser is not a bug:\r\n> Parentheses are used for symbol grouping and are strongly recommended whenever the order of operations might be subject to misinterpretation. A space character implies multiplication which can also be conveyed explicitly with an asterisk or a period. Therefore, although spaces are allowed as symbol separators, their use is discouraged.\r\n\r\nHowever, @mdboom, I was wondering if the parsing error or maybe even the parsing behaviour could be improved here. It is a bit confusing that spaces in the unit string are OK in some cases:\r\n```\r\nu.Unit('m /s') # space before is OK\r\nu.Unit('m / s1') # space before and after are OK if second operator has an exponent\r\nu.Unit('m / (s)') # spaces before and after are OK if second operator is in parentheses\r\nu.Unit('m    /  s1') # multiple spaces are OK where one space is OK\r\nu.Unit('m s') # space only means multiply, i.e. u.Unit('m*s')\r\n```\r\nBut spaces are not OK in these cases\r\n```\r\nu.Unit('m *s') # space before * not OK, was OK for /\r\nu.Unit('m/ s') # space after / is not OK\r\n```\r\n\r\nIs it possible (with reasonable effort) to make `u.Unit('m / s')` work or give a more explicit error message that whitespace is the problem? If not, obviously feel free to just close this issue since this is not a bug.\r\n\r\nNote that the CDS parser has it easy and gives\r\n```\r\nIn [113]: u.Unit('m / s', format='cds')\r\nERROR: ValueError: CDS unit must not contain whitespace [astropy.units.format.cds]\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/123396357","html_url":"https://github.com/astropy/astropy/pull/602#issuecomment-123396357","issue_url":"https://api.github.com/repos/astropy/astropy/issues/602","id":123396357,"user":{"login":"cdeil","id":852409,"avatar_url":"https://avatars.githubusercontent.com/u/852409?v=3","gravatar_id":"","url":"https://api.github.com/users/cdeil","html_url":"https://github.com/cdeil","followers_url":"https://api.github.com/users/cdeil/followers","following_url":"https://api.github.com/users/cdeil/following{/other_user}","gists_url":"https://api.github.com/users/cdeil/gists{/gist_id}","starred_url":"https://api.github.com/users/cdeil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdeil/subscriptions","organizations_url":"https://api.github.com/users/cdeil/orgs","repos_url":"https://api.github.com/users/cdeil/repos","events_url":"https://api.github.com/users/cdeil/events{/privacy}","received_events_url":"https://api.github.com/users/cdeil/received_events","type":"User","site_admin":false},"created_at":"2015-07-21T16:40:56Z","updated_at":"2015-07-21T16:40:56Z","body":"@embray Thanks for the quick comment. Let's continue the discussion here: #3986"}}