@@ -73,19 +73,10 @@ def _generate_staleness_report_per_image(
73
73
# Use previous month to get full month of data
74
74
previous_month = (datetime .now () - relativedelta (months = 1 )).strftime ("%Y-%m" )
75
75
pkg_list = list (package_versions_in_upstream .keys ())
76
-
77
- # Process packages individually to handle exceptions per package
78
- conda_download_stats = {}
79
- for pkg in pkg_list :
80
- try :
81
- # Suppress FutureWarning from pandas so it doesn't show in report
82
- with warnings .catch_warnings ():
83
- warnings .filterwarnings ("ignore" , category = FutureWarning )
84
- # Get stats for single package
85
- pkg_stats = overall ([pkg ], month = previous_month )
86
- conda_download_stats [pkg ] = pkg_stats .get (pkg , "N/A" )
87
- except ValueError as e :
88
- conda_download_stats [pkg ] = "N/A"
76
+ # Suppress FutureWarning from pandas so it doesn't show in report
77
+ with warnings .catch_warnings ():
78
+ warnings .filterwarnings ("ignore" , category = FutureWarning )
79
+ conda_download_stats = overall (pkg_list , month = previous_month )
89
80
90
81
for package in package_versions_in_upstream :
91
82
version_in_sagemaker_distribution = str (target_packages_match_spec_out [package ].get ("version" )).removeprefix (
@@ -105,23 +96,12 @@ def _generate_staleness_report_per_image(
105
96
}
106
97
)
107
98
108
- def sort_key (x ):
109
- # First key: False for stale packages (they start with "${\\color")
110
- is_current = not x ["package" ].startswith ("${\\ color" )
111
-
112
- # Second key: downloads count, with "N/A" treated as lowest priority
113
- downloads = x ["downloads" ]
114
- if downloads == "N/A" :
115
- download_value = float ('-inf' ) # Put N/A at the bottom
116
- else :
117
- try :
118
- download_value = float (downloads )
119
- except (ValueError , TypeError ):
120
- download_value = float ('-inf' ) # Handle any other non-numeric values
121
-
122
- return (is_current , download_value )
123
-
124
- staleness_report_rows .sort (key = sort_key , reverse = True )
99
+ staleness_report_rows .sort (
100
+ key = lambda x : (
101
+ not x ["package" ].startswith ("${\\ color" ), # Stale packages at top of list
102
+ - x ["downloads" ], # Sorted by downloads
103
+ )
104
+ )
125
105
print (
126
106
create_markdown_table (
127
107
[
0 commit comments