Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ projects:
- datomize
- gretel-trainer
- ydata-sdk
- mostlyai
- synthcity
- smartnoise-synth
- realtabformer
- be-great
7 changes: 5 additions & 2 deletions download_analytics/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ def _historical_groupby(downloads, groupbys=None):
if groupbys is None:
groupbys = downloads.set_index('timestamp').columns

new_columns = []
for groupby in groupbys:
grouped = downloads.groupby([year_month, groupby])
grouped_sizes = grouped.size().unstack(-1) # noqa: PD010
if len(groupbys) > 1:
grouped_sizes.columns = f"{groupby}='" + grouped_sizes.columns + "'"
new_columns.append(grouped_sizes.fillna(0))

base[grouped_sizes.columns] = grouped_sizes.fillna(0)
if new_columns:
base = pd.concat([base] + new_columns, axis=1)

totals = base.sum()
totals.name = 'total'
base = pd.concat([base, totals], ignore_index=True)
base = pd.concat([base, totals.to_frame().T], ignore_index=True)
Copy link
Collaborator

@gsheni gsheni Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add a transpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a bug that I introduced in the previous addition. totals is a series that was 'appended' to the frame and now we are using pd.concat I referenced to this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new output for total:

 base.reset_index().iloc[::-1]['total']
82    2011571.0
81       6536.0
80      65395.0
79      10876.0
78      57403.0
        ...    
4         435.0
3         569.0
2         187.0
1          93.0
0          60.0
Name: total, Length: 83, dtype: float64


return base.reset_index().iloc[::-1]

Expand Down
2 changes: 1 addition & 1 deletion download_analytics/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_pypi_downloads(
if max_date is None:
all_downloads = new_downloads
else:
if max_date < end_date:
if pd.Timestamp(max_date) < pd.Timestamp(end_date):
before = previous[previous.timestamp < new_downloads.timestamp.min()]
after = new_downloads
else:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ dependencies = [
"PyYAML",
"PyDrive",
"google-cloud-bigquery",
"db-dtypes"
"db-dtypes",
"httplib2==0.15.0", # https://stackoverflow.com/questions/59815620/gcloud-upload-httplib2-redirectmissinglocation-redirected-but-the-response-is-m
]

[project.urls]
Expand Down