-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
U/jrbogart/gaia slice #95
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine, but I do have a suggested change.
skycatalogs/objects/gaia_object.py
Outdated
ixdata = [i for i in range(min(key.stop, len(self._id)))] | ||
ixdata = [i for i in range(min(key.stop, len(self.df['id'])))] | ||
ixes = itertools.islice(ixdata, key.start, key.stop, key.step) | ||
return [self._object_class(self.df.iloc[i], self, i) for i in ixes] | ||
return [self.__getitem__(i) for i in ixes] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is fine, but it seems that the reason to use itertools.islice
would be to avoid creating the ixdata
list to begin with. The following should be equivalent, is clearer (to me at least), and also avoids creating an intermediate list.
return [self.__getitem__(i) for i in range(len(self.df))[key]]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. There is similar code in base_object.py and sso_object.py. I will update them similarly in upcoming commit.
skycatalogs/objects/gaia_object.py
Outdated
'dec_deg', | ||
'phot_bp_mean_flux', | ||
'phot_rp_mean_flux')} | ||
row = {col: self.df[col][key] for col in cols} | ||
return GaiaObject(row, self, key) | ||
|
||
elif type(key) == slice: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use isinstance(key, slice)
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason. I'll change it.
Fix code for retrieval of a GaiaCollection slice. It's unlikely anyone has or will use it, but, since GaiaCollection subclasses Sequence, it should handle this case.