String-formatted columns causing plot axis errors in NB 07a

An issue came up in the last DA, when Ryan led us through the latest version of Melissa’s 07a tutorial on DIAObject time series. In that notebook, a histogram plot was misrendered (a huge number of ticks). The problem ended up being caused by one of the attributes from a query being passed as a string to matplotlib, instead of as an array of floats.

About halfway through 07a, there’s an option to display the DiaObjs table. The displayed table shows that all attributes have type float64, except for rMagAmp, which for some reason was returned with type object (that’s what NumPy typically does for a column if it’s passed data of mixed types). It’s the rMagAmp histogram that MPL couldn’t handle. Changing the plot command to use a cast fixed it:

ax[1].hist(numpy.asarray(DiaObjs['rMagAmp'], float), bins=20, color=plot_filter_colors['r'])

I posted about this in Zoom chat, asking why that column had the object type, but it was at the end of the session and we didn’t get time to address it. This raises the question of understanding when a query may be expected to return a number, or instead a number rendered as a string.

1 Like

Thanks for the reminder on that issue @TomLoredo, I do indeed think I may have missed your comment on that in the chat on this. That’s a good question on why certain column values are getting read in as different types. I’ll look into that while I also try to address the plotting fixes for the 07a notebook.

I agree this is probably worth a separate thread.

1 Like

I’ve moved this into a separate thread, thanks both.