{"action":"created","issue":{"url":"https://api.github.com/repos/hgrecco/pint/issues/185","labels_url":"https://api.github.com/repos/hgrecco/pint/issues/185/labels{/name}","comments_url":"https://api.github.com/repos/hgrecco/pint/issues/185/comments","events_url":"https://api.github.com/repos/hgrecco/pint/issues/185/events","html_url":"https://github.com/hgrecco/pint/issues/185","id":41443540,"number":185,"title":"Defining your own dimensionless units","user":{"login":"foosa","id":1218437,"avatar_url":"https://avatars.githubusercontent.com/u/1218437?v=3","gravatar_id":"","url":"https://api.github.com/users/foosa","html_url":"https://github.com/foosa","followers_url":"https://api.github.com/users/foosa/followers","following_url":"https://api.github.com/users/foosa/following{/other_user}","gists_url":"https://api.github.com/users/foosa/gists{/gist_id}","starred_url":"https://api.github.com/users/foosa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foosa/subscriptions","organizations_url":"https://api.github.com/users/foosa/orgs","repos_url":"https://api.github.com/users/foosa/repos","events_url":"https://api.github.com/users/foosa/events{/privacy}","received_events_url":"https://api.github.com/users/foosa/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-08-28T21:08:20Z","updated_at":"2015-12-22T03:42:39Z","closed_at":"2015-12-22T03:42:39Z","body":"First off, I am a big fan of Pint and am using it in several of my projects.  I have  a question about defining custom dimensionless units.  As an example of what I am trying to do, consider how Pint behaves with `'pi'`:\r\n```python\r\nimport pint\r\n\r\nRegistry = pint.UnitRegistry()\r\nQuantity = Registry.Quantity\r\nprint(Quantity(1, 'pi').to('dimensionless'))\r\n```\r\nThis code snippet prints `3.14159265359 dimensionless`.  Now suppose I want to define a new constant representing the [electron g-factor](http://en.wikipedia.org/wiki/G-factor_%28physics%29) (or pick any other dimensionless physical constant).  I would suppose such a unit could be defined as follows:\r\n```python\r\nimport pint\r\n\r\nRegistry = pint.UnitRegistry()\r\nRegistry.define('electron_g_factor = -2.00231930436 * dimensionless = gs')\r\nQuantity = Registry.Quantity\r\n\r\n# Create a quantity with units of g_factors\r\ng = Quantity(1, 'gs')\r\nprint(g)\r\n\r\n# Convert g to dimenionless, similar to 'pi' (RAISES KeyError)\r\nprint(g.to('dimensionless'))\r\n```\r\nThe first print statement prints `1 electron_g_factor`.  I would expect the second statement to print `-2.00231930436 dimensionless` but instead it raises a `KeyError`. The second statement fails because Pint can't convert to a dimensionless quantity.  What gives?  How can I define a dimensionless unit that behaves like `'pi'`?\r\n"},"comment":{"url":"https://api.github.com/repos/hgrecco/pint/issues/comments/166497575","html_url":"https://github.com/hgrecco/pint/issues/185#issuecomment-166497575","issue_url":"https://api.github.com/repos/hgrecco/pint/issues/185","id":166497575,"user":{"login":"hgrecco","id":278566,"avatar_url":"https://avatars.githubusercontent.com/u/278566?v=3","gravatar_id":"","url":"https://api.github.com/users/hgrecco","html_url":"https://github.com/hgrecco","followers_url":"https://api.github.com/users/hgrecco/followers","following_url":"https://api.github.com/users/hgrecco/following{/other_user}","gists_url":"https://api.github.com/users/hgrecco/gists{/gist_id}","starred_url":"https://api.github.com/users/hgrecco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hgrecco/subscriptions","organizations_url":"https://api.github.com/users/hgrecco/orgs","repos_url":"https://api.github.com/users/hgrecco/repos","events_url":"https://api.github.com/users/hgrecco/events{/privacy}","received_events_url":"https://api.github.com/users/hgrecco/received_events","type":"User","site_admin":false},"created_at":"2015-12-22T03:42:39Z","updated_at":"2015-12-22T03:42:39Z","body":"I am closing this now. Feel free to reopen."}}