{"action":"created","issue":{"url":"https://api.github.com/repos/gammapy/gammapy/issues/781","repository_url":"https://api.github.com/repos/gammapy/gammapy","labels_url":"https://api.github.com/repos/gammapy/gammapy/issues/781/labels{/name}","comments_url":"https://api.github.com/repos/gammapy/gammapy/issues/781/comments","events_url":"https://api.github.com/repos/gammapy/gammapy/issues/781/events","html_url":"https://github.com/gammapy/gammapy/issues/781","id":189992525,"number":781,"title":"Changing the `.table` attribute breaks `SourceCatalog` indexing","user":{"login":"adonath","id":3715928,"avatar_url":"https://avatars.githubusercontent.com/u/3715928?v=3","gravatar_id":"","url":"https://api.github.com/users/adonath","html_url":"https://github.com/adonath","followers_url":"https://api.github.com/users/adonath/followers","following_url":"https://api.github.com/users/adonath/following{/other_user}","gists_url":"https://api.github.com/users/adonath/gists{/gist_id}","starred_url":"https://api.github.com/users/adonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adonath/subscriptions","organizations_url":"https://api.github.com/users/adonath/orgs","repos_url":"https://api.github.com/users/adonath/repos","events_url":"https://api.github.com/users/adonath/events{/privacy}","received_events_url":"https://api.github.com/users/adonath/received_events","type":"User","site_admin":false},"labels":[{"id":39740769,"url":"https://api.github.com/repos/gammapy/gammapy/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-17T09:42:59Z","updated_at":"2016-11-17T09:47:38Z","closed_at":null,"body":"Currently the `SourceCatalog` indexing by source name returns incorrect results, when the underlying `.table` attribute is changed in place, e.g. by sorting:\r\n\r\n```\r\nfrom gammapy.catalog import SourceCatalog2FHL\r\nfermi_2fhl = SourceCatalog2FHL()\r\n\r\nprint(fermi_2fhl['2FHL J0033.6-1921'])\r\n\r\nfermi_2fhl.table.sort('GLON')\r\n\r\nprint(fermi_2fhl['2FHL J0033.6-1921'])\r\n```\r\n\r\nWhich yields:\r\n```\r\nSource: 2FHL J0033.6-1921\r\n\r\nRA (J2000)  : 8.41149997711\r\nDec (J2000) : -19.3575000763\r\nGLON        : 94.2800216675\r\nGLAT        : -81.222366333\r\n\r\n\r\nSource: 2FHL J1801.3-2326e\r\n\r\nRA (J2000)  : 270.339996338\r\nDec (J2000) : -23.4400005341\r\nGLON        : 6.52657604218\r\nGLAT        : -0.25105163455\r\n```\r\n\r\nI think this behaviour should be fixed, because it is common use case e.g. to look for the 10 highest significant or largest sources in a catalog."},"comment":{"url":"https://api.github.com/repos/gammapy/gammapy/issues/comments/261201510","html_url":"https://github.com/gammapy/gammapy/issues/781#issuecomment-261201510","issue_url":"https://api.github.com/repos/gammapy/gammapy/issues/781","id":261201510,"user":{"login":"adonath","id":3715928,"avatar_url":"https://avatars.githubusercontent.com/u/3715928?v=3","gravatar_id":"","url":"https://api.github.com/users/adonath","html_url":"https://github.com/adonath","followers_url":"https://api.github.com/users/adonath/followers","following_url":"https://api.github.com/users/adonath/following{/other_user}","gists_url":"https://api.github.com/users/adonath/gists{/gist_id}","starred_url":"https://api.github.com/users/adonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adonath/subscriptions","organizations_url":"https://api.github.com/users/adonath/orgs","repos_url":"https://api.github.com/users/adonath/repos","events_url":"https://api.github.com/users/adonath/events{/privacy}","received_events_url":"https://api.github.com/users/adonath/received_events","type":"User","site_admin":false},"created_at":"2016-11-17T09:47:38Z","updated_at":"2016-11-17T09:47:38Z","body":"A possible fix could be to use `Table` advanced indexing. Here's a minimal example:\r\n\r\n```\r\nfrom astropy.table import Table\r\nt = Table([('one', 'two', 'three', 'four'), (8, 7, 6, 5)], names=('a', 'b'))\r\nt.add_index('a')\r\n\r\nprint(t.loc['two'])\r\n\r\nt.sort('b')\r\n\r\nprint(t.loc['two'])\r\n```\r\n\r\nWhich returns:\r\n```\r\n a   b \r\n--- ---\r\ntwo   7\r\n a   b \r\n--- ---\r\ntwo   7\r\n\r\n```"}}
{"actor":{"display_login":"adonath"}}