{"action":"created","issue":{"url":"https://api.github.com/repos/astropy/astropy/issues/4674","repository_url":"https://api.github.com/repos/astropy/astropy","labels_url":"https://api.github.com/repos/astropy/astropy/issues/4674/labels{/name}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/4674/comments","events_url":"https://api.github.com/repos/astropy/astropy/issues/4674/events","html_url":"https://github.com/astropy/astropy/issues/4674","id":139220905,"number":4674,"title":"inconsistency after deleted columns","user":{"login":"Doidel","id":833039,"avatar_url":"https://avatars.githubusercontent.com/u/833039?v=3","gravatar_id":"","url":"https://api.github.com/users/Doidel","html_url":"https://github.com/Doidel","followers_url":"https://api.github.com/users/Doidel/followers","following_url":"https://api.github.com/users/Doidel/following{/other_user}","gists_url":"https://api.github.com/users/Doidel/gists{/gist_id}","starred_url":"https://api.github.com/users/Doidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Doidel/subscriptions","organizations_url":"https://api.github.com/users/Doidel/orgs","repos_url":"https://api.github.com/users/Doidel/repos","events_url":"https://api.github.com/users/Doidel/events{/privacy}","received_events_url":"https://api.github.com/users/Doidel/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/astropy/astropy/labels/io.fits","name":"io.fits","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-08T09:11:31Z","updated_at":"2016-03-09T13:40:15Z","closed_at":null,"body":"I noticed after deleting some columns from a FITS_rec (e.g. `v.columns.del_col('SIGAMP')`) there are some inconsistency issues in FITS_rec:\r\n```\r\ndef __setitem__(self, key, value):\r\n        ...\r\n        if isinstance(value, FITS_record):\r\n            for idx in range(self._nfields):\r\n                self.field(self.names[idx])[key] = value.field(self.names[idx])\r\n```\r\nHere `self.dtype.names` and `self._nfields` still have the original (deleted) column names, while `self.names` doesn't. This leads to an error in the above code (out of bounds) when `idx` grows larger than `self.names`.\r\n\r\nI haven't checked whether this issue also appears in other occasions.\r\n\r\nThanks and kind regards"},"comment":{"url":"https://api.github.com/repos/astropy/astropy/issues/comments/194300196","html_url":"https://github.com/astropy/astropy/issues/4674#issuecomment-194300196","issue_url":"https://api.github.com/repos/astropy/astropy/issues/4674","id":194300196,"user":{"login":"Doidel","id":833039,"avatar_url":"https://avatars.githubusercontent.com/u/833039?v=3","gravatar_id":"","url":"https://api.github.com/users/Doidel","html_url":"https://github.com/Doidel","followers_url":"https://api.github.com/users/Doidel/followers","following_url":"https://api.github.com/users/Doidel/following{/other_user}","gists_url":"https://api.github.com/users/Doidel/gists{/gist_id}","starred_url":"https://api.github.com/users/Doidel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Doidel/subscriptions","organizations_url":"https://api.github.com/users/Doidel/orgs","repos_url":"https://api.github.com/users/Doidel/repos","events_url":"https://api.github.com/users/Doidel/events{/privacy}","received_events_url":"https://api.github.com/users/Doidel/received_events","type":"User","site_admin":false},"created_at":"2016-03-09T13:40:15Z","updated_at":"2016-03-09T13:40:15Z","body":"Yes, I uploaded a zip containing the code and a fits file here: http://www.filedropper.com/testcasedelcolumns_1\r\nor, alternatively, here is the code snippet alone:\r\n```\r\nfrom __future__ import print_function\r\nfrom astropy.io import fits\r\n\r\nif __name__ == \"__main__\":\r\n    hdu_list = fits.open('visibilitybag_photon.fits', memmap=False)\r\n    v = hdu_list[1].data\r\n\r\n    v.columns.del_col('HARM')\r\n    v.columns.del_col('SIGAMP')\r\n    v.columns.del_col('TYPE')\r\n    v.columns.del_col('UNITS')\r\n    v.columns.del_col('ATTEN_STATE')\r\n    v.columns.del_col('COUNT')\r\n\r\n    #vislist._nfields = len(vislist.names)  # workaround for FITS_rec bug, https://github.com/astropy/astropy/issues/4674\r\n    ##vislist.dtype.names = tuple(vislist.names)\r\n\r\n    # For demonstrating purposes: Replacing last FITS_record with first FITS_record\r\n    v[len(v) - 1] = v[0]\r\n```"}}