Skip to content
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

Merged
merged 3 commits into from
May 9, 2024
Merged

U/jrbogart/gaia slice #95

merged 3 commits into from
May 9, 2024

Conversation

JoanneBogart
Copy link
Collaborator

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.

@JoanneBogart JoanneBogart marked this pull request as ready for review May 3, 2024 21:55
@JoanneBogart JoanneBogart requested a review from jchiang87 May 3, 2024 21:55
Copy link
Collaborator

@jchiang87 jchiang87 left a 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.

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]
Copy link
Collaborator

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]]

Copy link
Collaborator Author

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.

'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:
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@JoanneBogart JoanneBogart merged commit 87a11c7 into main May 9, 2024
1 check passed
@JoanneBogart JoanneBogart deleted the u/jrbogart/gaia_slice branch May 9, 2024 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants