M2_UGL_1 - Regenerated Chart V2 is created with no graph plot in it

hello everyone according to staff update, the issue is resolved, try to launch the notebook again lassroom page, in case you still find same issue, please make sure to clear your kernel output, delete any browsing history, and try again.

Let me know if issue still persist for anyone

Hi Deepti, I am still seeing this error even after clearing kernel output, etc.

TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'str'

It is coming from this generated code from the exercise block:

import pandas as pd
import matplotlib.pyplot as plt

# Filter data for Q1 of 2024 and 2025
df['date'] = pd.to_datetime(df['date'] + ' ' + df['year'].astype(str))
q1_2024 = df[(df['year'] == 2024) & (df['quarter'] == 1)]
q1_2025 = df[(df['year'] == 2025) & (df['quarter'] == 1)]

Let me know how to get around it. Thanks!

did you try refreshing the notebook??

Try clearing the kernel output and reconnect the kernel, run the cell from starting, let me know if issue still persist

Hi Deepti, yes I have tried all those things: restart the notebook, manually “restart and clear output” for Kernel and repeatedly running the cell from the start of the notebook to that session multiple times but to no avail. Please help resolve

I’m also experiencing issues with the exec function:

TypeError: unsupported operand type(s) for +: 'DatetimeArray' and 'str'

Any update?

TypeError Traceback (most recent call last)
Cell In[5], line 7
5 utils.print_html(initial_code, title=“Extracted Code to Execute”)
6 exec_globals = {“df”: df}
----> 7 exec(initial_code, exec_globals)

@lesly.zerna

Please look into this issue, looks like the issue still not resolved.

@tinnilarh

can you make change to df code where astype(str) is used, instead of tuple, use square brackets for the first code line, do you still get the same error??

In this context, the ‘+’ operator will only concatenate string objects. If you have a string and anything else, it will throw an error.

I am not sure how to edit the LLM generated code block to change the syntax but I added an additional code generation prompt line to specifically avoid this error. Then the generated code block no longer has this syntax error. Thanks for the pointer!

1 Like

there is surely a bug here probably needs some change in the metadata.

I have pinged L.T. of the course.

please wait for lesly’s response.

I tried switching to to GPT-4.1-mini for the first graph and got error that this model is invalid.

@lesly.zerna, is this issue still in-work?

Hello TMosh! Thanks for recalling about this ungraded lab! - I get how frustrating it can be when the lab doesn’t run properly.

In this lab, remember that the LLM actually writes code that’s then executed to make the chart. Sometimes it doesn’t format the code correctly.

Try these quick fixes:

  • Run the cell again (often works on the second or third try).

  • Make a tiny change in your prompt or code so the LLM regenerates fresh output. (I, myself, am testing the generated code by the LLM in a colab notebook to test the result and so and how I can improve the prompt to get it working)

If it still fails, it’s likely the model just produced incorrect code — totally normal for some models. We’ll add a note about that in the lab. Thanks for catching this and helping us improve! :raising_hands:

I’d also add this “kind of” warning in the prompt:

"remove/avoid the line that attempts to combine the date and year string, as the date column already contains the complete date information."

Hi everyone. Even adding this to te prompt errors continue with KeyError: ‘year’ responsible. Is frustating this happen at the very beginning.

We’ve been testing with the team, and tried changing it to

"Create a plot that compares Q1 coffee sales in 2024 and 2025 using the data in coffee_sales.csv." 

and it is giving us working code.

It’s sensitive to the prompt, as you can see!

hi @lesly.zerna does this mean LLM is not able to understand that 2024 is a year designation??

it’s interesting to see that LLM cannot differentiate between date and year :thinking:

It works.
Many Thanks

1 Like

Key here is modifying the prompt to avoid type exception , we can instruct write a code in such way that we avoid type error - an did worked for me
while this is perfectly fine - I think we can modify the problematic code line ourself - use the model output extracted code string , correct it and store in same variable - this also works

1 Like

Hello Lesly,
I put your “kind of” warning in the prompt and also told it: do not try to add together any Datetime strings. These two “kind of” warnings seemed to be enough to convince it of the nature of the code I required!
I’m newish to Python so I got chatgpt to interpret the error messages I was getting instead of a plot.
Cheers!

1 Like

good one you are finding ways to improve your prompt and getting better answers!