Skip to content
11 min read plotly plotting datetime parquet cleaning joins

Bamboo Weekly #199: Agentic PRs (solutions)

Get better at: Working with Parquet files, joins, plotting with Plotly, grouping, dates and times, and cleaning.

Bamboo Weekly #199: Agentic PRs (solutions)

The software industry is changing, quickly and dramatically, in front of our eyes. Just a few days ago, at a conference I attended, one speaker asked who had written code by hand in the last few months. Maybe a few hands went up, but I didn't see any. We're in the age of agentic coding, meaning that AI is now writing a growing proportion of our code.

But coding isn't just about writing. It's also about collaborating and communicating. And over the last two decades, GitHub has been at the forefront of such collaboration, whether it's on open-source projects or commercial ones. It did this not only by providing an easy-to-use central server for Git repositories, but also by inventing the "pull request," allowing someone to suggest (rather than force) a contribution to a Git repository.

A recent study by Harvard economists Fiona Chen and James Stratton examined the use of AI among software developers, including their use of AI in pull requests (https://fion.ac/jellyfish.pdf). This paper's data isn't available, but it did pique my curiosity, and I was delighted to discover that researcher Hao Li from Queen's University in Kingston, Ontario, Canada (https://leo-lihao.github.io) has a data set about GitHub pull requests, keeping track of those that were submitted by AI agents.

This week, we'll look at Li's data set, learning something about GitHub, about agentic coding, and the growing trends in the software industry.

Data and five questions

The data comes from Hao Li's data archive, which is stored on Hugging Face (https://huggingface.co/hao-li). We'll look at the 7.6M version of the data (https://huggingface.co/datasets/hao-li/AIDev-7.6M). Specifically, you'll only need a handful of files, all in Parquet format:

These files are too big for me to send with this message, so I'm afraid that even paid BW subscribers will need to download them from Hugging Face.

Paid subscribers, both to Bamboo Weekly and to my LernerPython+data membership program (https://LernerPython.com) get all of the questions and answers, as well as downloadable data files, downloadable versions of my notebooks, one-click access to my notebooks, and invitations to monthly office hours.

Learning goals for this week include: Parquet files, joins, plotting with Plotly, grouping, dates and times, and cleaning.

Here are my solutions and explanations for this week's five questions:

Read all four Parquet files into a Pandas data frames. Which project had the earliest pull request in the data set? Who made that pull request?

I started off by importing not only Pandas and Plotly Express (as usual), but also pathlib, which is a great way to work with filenames in the Python standard library:

import pandas as pd
from plotly import express as px
from pathlib import Path

I store my Bamboo Weekly notebooks and data in a Git repository that I store on GitHub — and because GitHub forbids files that are more than 100 MB in size, I didn't want to keep these files in there. So after downloading the files from Hugging Face, I kept them in my Downloads directory, and then set the four filename directories based on them:

data_directory = Path('/Users/reuven/Downloads/')

pull_request_filename = data_directory / 'pull_request.parquet'
pr_reviews_filename = data_directory / 'pr_reviews.parquet'
repository_filename = data_directory / 'repository.parquet'
pr_timeline_filename = data_directory / 'pr_timeline.parquet'

Notice one of the coolest features of pathlib, namely that you use the / character — which we normally associate with division — to combine a directory name and a filename. This is possible because data_directory is a Path object, not just a string.

I then needed to create four different Pandas data frames. In theory, I could do that by invoking pd.read_parquet on each file, and turning that into a data frame. And indeed, that would have worked just fine, especially since Parquet is a binary data format, meaning that Pandas doesn't need to turn the data from text into integers, floats, and dates.

But it turns out that the dates in these Parquet files weren't actually stored as datetime values. Which means that they were all str dtypes. Upon loading each file, I then used assign along with pipe along with pd.col and to_datetime in order to get datetime values in those columns:

pull_request_df = (
    pd
    .read_parquet(pull_request_filename)
    .assign(created_at = pd.col('created_at').pipe(pd.to_datetime),
            closed_at = pd.col('closed_at').pipe(pd.to_datetime),
            merged_at = pd.col('merged_at').pipe(pd.to_datetime))
)

pr_reviews_df = (
    pd
    .read_parquet(pr_reviews_filename)
    .assign(submitted_at = pd.col('submitted_at').pipe(pd.to_datetime))
)

repository_df = pd.read_parquet(repository_filename)

pr_timeline_df = (
    pd
    .read_parquet(pr_timeline_filename)
    .assign(created_at = pd.col('created_at').pipe(pd.to_datetime))
)

I then had four Pandas data frames:

Given these four data frames, how can we find out which project had the earlier pull request, and who made it?

I started off with pr_timeline_df, and used nsmallest to grab the row in which created_at was the smallest. This returned a one-row data frame. Fortunately, we can invoke merge on a data frame by specifying the column from the left (pr_id) and the column from the right (id). The result? Another data frame.

And on that second data frame? I then invoked merge a second time, matching the column on the left (repo_id) and the one on the right (id). The resulting data frame had a single row, which I then retrieved with loc[0] – not because we had to, but because it allowed us to see the information in that row in vertical form:


(
    pr_timeline_df
    .nsmallest(columns='created_at', n=1)
    .merge(pull_request_df, left_on='pr_id', right_on='id')
    .merge(repository_df, left_on='repo_id', right_on='id')
    .loc[0]
)

The result contained many values, including the message column, which had a great deal of text and body, which also had a lot of text. I removed both using drop, not because the text is uninteresting, but because it makes the data difficult to display, when we were looking for the repo and author information:

(
    pr_timeline_df
    .nsmallest(columns='created_at', n=1)
    .merge(pull_request_df, left_on='pr_id', right_on='id')
    .merge(repository_df, left_on='repo_id', right_on='id')
    .loc[0]
    .drop(index=['body', 'message'])
)

The result:

	0
pr_id	2756921963
event	commented
commit_id	
created_at_x	2024-12-24 00:23:13+00:00
actor	devin-ai-integration[bot]
assignee	
label	
id_x	2756921963
number	603
title	Add LLM Integration Tests
agent	Devin
user_id	158243242
user	devin-ai-integration[bot]
state	closed
created_at_y	2024-12-24 00:23:09+00:00
closed_at	2025-01-09 11:13:02+00:00
merged_at	
repo_id	679017521
repo_url	https://api.github.com/repos/AgentOps-AI/agentops
html_url	https://github.com/AgentOps-AI/agentops/pull/603
id_y	679017521
url	https://api.github.com/repos/AgentOps-AI/agentops
license	MIT
full_name	AgentOps-AI/agentops
is_forked	False
language	Python
forks	562
stars	5449

We can see that this was from the AgentOps-AI user's agentops repo on GitHub. The pull request was created on December 24, 2024, and the user was devin-ai-integration[bot], which pretty clearly identifies as a bot.

Notice that this is actually a "commented" event, which isn't exactly the start of a pull request. But it is the earlier item in our data set.

Notice that some of the columns appear twice, once with _x after the column name, and sometimes with _y after the column name. That shows where merge had the same column name on the left and right; join will complain and refuse to have conflicted names, whereas merge will add x and y suffixes so that we don't mix them up.

What proportion of pull requests were closed? On average, how long did it take for a PR to be created, merged, and then closed?

To answer the first question, I got the state column from pull_request_df. I then invoked value_counts on state, passing normalize=True in order to get the proportion, rather than the raw numbers. I also used round to keep only two numbers after the decimal point:


(
    pull_request_df
    ['state']
    .value_counts(normalize=True)
    .round(2)
)

The result:

state	proportion
closed	0.92
open	0.08

So in this data set, at least, we see that 92 percent of the pull requests were closed. However, I'm not sure if that's completely accurate. I mean, when was this measured, exactly? I would think that a pull request would have both open and closed states at various points of its lifetime, but the pull_request_df data set didn't reflect that.

I tried a different query:

(
    pr_timeline_df
    .pivot_table(index='pr_id',
                columns='event',
                values='commit_id',
                aggfunc='count')

)

And this did show me the number of times that each pull request entered different states, thanks to different events. But the number of event types was so large that it was impossible to read the output in a reasonable way.

I thus turned to the next question, namely how long it took for a PR to be created, merged, and then closed.

I first removed (using dropna) any rows in which created_at, closed_at, or merged_at were NaT, the datetime equivalent of NaN. Then I used the new select method to keep not just the id column, but to create three new columns – create_to_close (a timedelta), create_to_merge (another timedelta), and then close_and_merge_identical (a boolean):

(
    pull_request_df
    .dropna(subset=['created_at', 'closed_at', 'merged_at'])
    .select('id', 
           create_to_close = pd.col('closed_at') - pd.col('created_at'),
           create_to_merge = pd.col('merged_at')   - pd.col('created_at'),
           close_and_merge_identical = pd.col('closed_at')  == pd.col('merged_at')
          )
)

This gave me a data frame with 246,777 rows and 4 columns.

How often was a PR merged and closed at the same time? We can find out:

(
    pull_request_df
    .dropna(subset=['created_at', 'closed_at', 'merged_at'])
    .select('id', 
           create_to_close = pd.col('closed_at') - pd.col('created_at'),
           create_to_merge = pd.col('merged_at')   - pd.col('created_at'),
           close_and_merge_identical = pd.col('closed_at')  == pd.col('merged_at'))
    ['close_and_merge_identical']
    .value_counts(normalize=True)
    .round(2)
)

The result:

close_and_merge_identical	proportion
True	0.94
False	0.06

In other words, pull requests are merged and closed at the same time 94 percent of the time — which makes sense to me.

But how long from creation time to merge/close?

(
    pull_request_df
    .dropna(subset=['created_at', 'closed_at', 'merged_at'])
    .select('id', 
           create_to_close = pd.col('closed_at') - pd.col('created_at'),
           create_to_merge = pd.col('merged_at')   - pd.col('created_at'),
           close_and_merge_identical = pd.col('closed_at')  == pd.col('merged_at'))
    ['create_to_close']
    .agg(['mean', 'median'])

)

The result:

	create_to_close
mean	1 days 19:11:11.113746
median	0 days 00:52:53.000000

In other words: The mean is nearly 2 days. But it would seem that a small number of long times pull that up. And indeed, I found that the longest time before a pull request was closed was ... 382 days and nearly 15 hours — so the next time you feel guilty about not having handled a PR faster, you can feel better!

The median, meanwhile, is less than one hour (!), which is obviously much shorter and more reasonable.