Act fast, special offers end soon! Up to $294 is savings when you get Premium today.
Get offer codes

Problem with output evaluation

Hello,

I got a problem with output types on the mode mission.

Screen Link: https://app.dataquest.io/m/307/the-mode/5/special-cases

My code:

def mode_intervals(array):
   interval_left = gr_freq_table.idxmax().left
   interval_right = gr_freq_table.idxmax().right
   interval_range = interval_right-interval_left
   
   mode = interval_left + interval_range/2
   return int(mode)

   
mode = mode_intervals(gr_freq_table)

mean = houses["SalePrice"].mean()
median = houses["SalePrice"].median()

sentence_1 = mode < median < mean
sentence_2 = mean > median > mode

What I expected to happen: Both sentences should be “True”.

What actually happened: But an error occurs for sentence_1: Instead of bool_ we expected bool.

So why are there 2 outcomes of the same logic? Why it mixes numpy and python booleans?
If I do:

sentence_1 = bool(mode < median < mean)
sentence_2 = mean > median > mode

the problem is solved.

Best wishes

Hi @janmorbach, this is a bit strange indeed, and I confirm that the platform returns sentence_1 as a numpy.bool_. I was not able to reproduce this locally – I used your code, and sentence_1 was bool, not numpy.bool_.

To answer your question, I don’t think there should be two different outcomes here, just one: bool. This unexpected behavior might be caused by some hidden state running in the background or there might be some versioning issue, which means we’ll need to investigate this further. Thanks for pointing this out!

1 Like