Questions and notes from workshop day 6

Icebreaker :ice_cream:

What programming language(s) are you normally working with (add an o for your answer):

What does testing your code mean for you? How do you test?

Automated testing

Ask your questions here:

There will be two exercises during this session, see day 6: https://coderefinery.github.io/2026-03-17-workshop/exercises/ To do the exercises with the instructors in Python, you will need pytest installed, check our installation instructions You can also follow the exercise in R, Julia, C++

Motivation

Questions continued:

Testing locally

:::info

Exercise until xx:36

Material: https://coderefinery.github.io/testing/locally/#exercise

Goal: Write a test for a simple function, run it, break it (exercise Local-1)

:::

Questions continued:

:::info

Break until xx:06

After the break we will have another exercises. If you would like to try it, please fork and clone this repository https://github.com/lucaferranti/example-ci

:::

Automated testing

Luca currently showing: https://github.com/lucaferranti/example-ci Following the steps listed here: https://coderefinery.github.io/testing/continuous-integration/#continuous-integration Now you can connect with skills you learned in week one of this workshop :)

Questions continued:

Test design

:::info

Exercise until xx:40

Material (Design-6): https://coderefinery.github.io/testing/test-design/#test-driven-development

In the language of your choice: first write the test for the fizzbuzz function, then write the function. (solutions available for Python, R, Julia, C++, Fortran) We will show it afterwards using Python.

:::

Questions continued:

You can find some Conclusions and recommendations in our lesson materials

:::info

Longer break coming up, back at 13 CET / 14 EET

Coming up after the break: modular code development, no exercises but interactive type along :)

:::

Modular Code Development

Questions continued:

:::info

Discussion session until xx:25

Classrooms can discuss the questions below offline, others please answer below :)

:::

A. What does "modular code development" mean for you?

B. What best practices can you recommend to arrive at well structured, modular code in your favourite programming language?

C. What do you know now about programming that you wish somebody told you earlier?

D. Do you design a new code project on paper before coding? Discuss pros and cons.

E. Do you build your code top-down (starting from the big picture) or bottom-up (starting from components)? Discuss pros and cons.

F. Would you prefer your code to be 2x slower if it was easier to read and understand?

Your questions continued:

Modular Code in action

To code along, you can find the instructions in our lesson materials: https://coderefinery.github.io/modular-type-along/starting-point/ You can also just lean back and watch In case you would like to learn more about Jupyter Notebooks, check out our lesson: https://coderefinery.github.io/jupyter/

Questions continued:


import pandas as pd
import matplotlib.pyplot as plt


# read data
data = pd.read_csv("weather_data.csv")

# combine 'date' and 'time' into a single column 'recorded_at' as type datetime
data["recorded_at"] = pd.to_datetime(data["date"] + " " + data["time"])

# set 'recorded_at' as index for convenience
data = data.set_index("recorded_at")

def plotdata(x, y, y_label, location_label, color, *, show_y_mean=False):
    fig, ax = plt.subplots()
    
    # temperature time series
    ax.plot(
        x,
        y,
        label=y_label,
        color=color,
    )

    if show_y_mean:
        values = y.values
        mean_temp = sum(values) / len(values)
        
        # mean temperature (as horizontal dashed line)
        ax.axhline(
            y=mean_temp,
            label=f"mean {y_label}: {mean_temp:.1f}",
            color=color,
            linestyle="--",
        )
    
    ax.set_title(f"{y_label} at {location_label}")
    ax.set_xlabel("date and time")
    ax.set_ylabel(y_label)
    ax.legend()
    ax.grid(True)
    
    # format x-axis for better date display
    fig.autofmt_xdate()

    return fig


MONTHS = ["2024-01", "2024-02"]

for month in MONTHS:
    # keep only january data using datetime period indexing
    january = data.loc[month]

    fig = plotdata(
        january.index,
        january["air_temperature_celsius"],
        "air temperature (C)",
        "Helsinki airport",
        "red",
        show_y_mean=True
    )
    
    fig.savefig(f"{month}-temperature.png")

    fig = plotdata(
        january.index,
        january["precipitation_mm"],
        "precipitation (mm)",
        "Helsinki airport",
        "blue"
    )
        
    fig.savefig(f"{month}-precipitation.png")
- Thank you!

:::info

Break until xx:00 (15 EET, 14 CET)

:::

Interaction possibility for the audience; what should Frankie do next to get to more modular code? Add your suggestions.

Questions continued:

Question: how can we sure that we don't break something during the modularization?

Feedback day 6

Today was (vote for all that apply):

too fast:o too slow: right speed:ooooooooo too slow sometimes, too fast other times: o too advanced: too basic: right level:ooooo I will use what I learned today: oooooooo I would recommend today to others: ooooooo I would not recommend today to others:

One good thing about today:

One thing to improve for next time:

Any other feedback? General questions?



Funding

CodeRefinery is a project within the Nordic e-Infrastructure Collaboration (NeIC).

Privacy

Privacy policy

Follow us

Contact

support@coderefinery.org

Improve this page

Source code