Sea level predictor Test Error

Hi learning partners!.
I am doing my testing of Sea level predictor and I getting the error
“AttributeError: ‘Line2D’ object has no attribute ‘get_offsets’” for the testing instruction “actual = self.ax.get_children()[0].get_offsets().data.tolist()”.

My code:
‘’’

Create first line of best fit

results = linregress(x, y)  # Creates Linear regression storing in "results" the different properties
years_add1 = list(range(1880, 2049))
ext_line1 = [results.intercept + results.slope * xi for xi in years_add1]

# Create second line of best fit
df_2000 = df.loc[df['Year'] >= 2000, ['Year', 'CSIRO Adjusted Sea Level']]
x2 = df_2000.Year
y2 = df_2000['CSIRO Adjusted Sea Level']
results2 = linregress(x2, y2)
years_add2 = list(range(2000, 2049))
ext_line2 = [results2.slope * xi + results2.intercept for xi in years_add2]'''

Any suggestions?. Thank you in advance!.

I suggest reading the error message, because it contains the line of code where the error is happening and the code you posted does not contain that line :wink:

Also the error message is self-explanatory. You use a .get_offsets() which doesn’t seem to exist in this context.

Thank you for your answer. The line with the error is in the Test code module. I didn’t put it because I understand we are in the context of the project “Sea level predictor”. About the second part, I am using the requested modules, that’s why I don’t understand why the test is requesting a property that seems not to exist!. :grinning:

Well if the error is from the test module, your return value is most likely wrong.
Without seeing the entire code though, I can’t really help you.

I mean, pretty sure you are supposed to plot something there but your code does not contain any plots.

Did you figure it out?
As @Jagaya said, the get_offset is connected to the plot. The test_module.py calls your draw_plots() method, and expects a figure containing the scatter plot and the two line fits. The self.ax.get_children()[0].get_offsets() from the error message refers in principle to the scatter plot - but for you it seems to be a Line2D object instead. Maybe you are plotting things in the wrong order?

Hi. Yes, I solved. I had to change the way I was calling the linregress function to “slope, intercept, r_value, p_value, std_err = linregress(x,y)” which I understand is used for backward compatibility. I was trying it to work as “results=linregress(x, y)”, but it didn’t work. As I am learning, I didn’t really understand the why, but that was the way I solved it!. Thank you!.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.