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

DM-34082: Handle empty arrays #27

Merged
merged 4 commits into from Mar 16, 2022
Merged

DM-34082: Handle empty arrays #27

merged 4 commits into from Mar 16, 2022

Conversation

arunkannawadi
Copy link
Member

No description provided.

@@ -502,9 +503,12 @@ def scatterPlotWithTwoHists(self, catPlot, plotInfo, sumStats, yLims=False, xLim
ax.set_ylim(yLims[0], yLims[1])
else:
if len(ysStars) > 0:
[ys1, ys99] = np.nanpercentile(ysStars, [1, 99])
[ys1, ys99] = np.nanpercentile(ysStars, [1, 99]) # noqa: F841
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variables are not used anywhere and makes flake8 unhappy. I could remove this, but I don't want to since I don't know what is was intended for, and I just want to get it in by tonight.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @erykoff , the force push was introducing these noqa comments since the linting failed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, just delete the whole section then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how did this ever pass linting? Anyway, these should be deleted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out if you defined something like [ys1, ys99] = [blah, blah], then it's okay according to F841. But if I made it ys1, ys99 = blah, blah (as I do now) and don't use ys1 and ys99, then flake8 is unhappy. That's how it passed the linting previously.

Copy link
Contributor

@erykoff erykoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but more keeps coming in!

@@ -217,6 +217,9 @@ def colorColorFitPlot(self, catPlot, plotInfo, fitParams):
ys = catPlot[self.config.axisLabels["y"]].values
mags = catPlot[self.config.axisLabels["mag"]].values

if len(xs) == 0 or len(ys) == 0:
return fig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to see how the length of xs and ys could differ, but I guess it doesn't hurt to check both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't either, but this is the first time I am seeing this code, so I am being extra cautious.

galPoints = ax.scatter(xsGalaxies, ysGalaxies, c=zsGalaxies, cmap=newReds, label="Galaxies",
s=0.5, vmin=vminGals, vmax=vmaxGals)
else:
galPoints = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a style choice, I think a blank line would be nice here. But not necessary of course.

starPercsY = np.nanpercentile(ysStars, [1, 99.5])
pad = (starPercsX[1] - starPercsX[0])/10
ax.set_xlim(starPercsX[0] - pad, starPercsX[1] + pad)
ax.set_ylim(starPercsY[0] - pad, starPercsY[1] + pad)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have any stars, what happens to the limits? (Though better than crashing!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example case I had had both stars and galaxies list empty. So the axis limits were [0,1] in both directions. I suppose matplotlib still autoscales the limits so they are not going to be totally useless.

@arunkannawadi arunkannawadi merged commit aa635fc into main Mar 16, 2022
@arunkannawadi arunkannawadi deleted the tickets/DM-34082 branch March 21, 2022 14:41
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.

None yet

2 participants