@@ -594,8 +594,16 @@ def _aim_analysis(self):
594594 def _parse_aim_metadata (
595595 self , sample_set : str , data : Union [bytes , Exception ]
596596 ) -> pd .DataFrame :
597- assert self ._aim_metadata_columns is not None
598- assert self ._aim_metadata_dtype is not None
597+ if self ._aim_metadata_columns is None :
598+ raise RuntimeError (
599+ "Internal error: AIM metadata columns are not configured. "
600+ "This should not happen; please open a GitHub issue."
601+ )
602+ if self ._aim_metadata_dtype is None :
603+ raise RuntimeError (
604+ "Internal error: AIM metadata dtypes are not configured. "
605+ "This should not happen; please open a GitHub issue."
606+ )
599607 if isinstance (data , bytes ):
600608 # Parse CSV data but don't apply the dtype yet.
601609 df = pd .read_csv (io .BytesIO (data ), na_values = "" )
@@ -971,6 +979,8 @@ def plot_samples_interactive_map(
971979 fill_value = 0 ,
972980 )
973981
982+ taxa = df_pivot .columns .dropna ().sort_values ().unique ()
983+
974984 # Append aggregations to pivot.
975985 df_location_aggs = df_samples .groupby (location_composite_key ).agg (
976986 {
@@ -1015,7 +1025,6 @@ def plot_samples_interactive_map(
10151025 samples_map .layout .width = width
10161026
10171027 # Add markers.
1018- count_factors = df_samples [count_by ].dropna ().sort_values ().unique ()
10191028 for _ , row in df_pivot .reset_index ().iterrows ():
10201029 title = (
10211030 f"Location: { row .location } ({ row .latitude :.3f} , { row .longitude :.3f} )"
@@ -1028,13 +1037,13 @@ def plot_samples_interactive_map(
10281037 title += f"\n Contributors: { row .contributor } "
10291038 title += "\n No. specimens: "
10301039 all_n = 0
1031- for factor in count_factors :
1040+ for taxon in taxa :
10321041 # Get the number of samples in this taxon
1033- n = row [factor ]
1042+ n = int ( row [taxon ])
10341043 # Count the number of samples in all taxa
10351044 all_n += n
10361045 if n > 0 :
1037- title += f"{ n } { factor } ; "
1046+ title += f"{ n } { taxon } ; "
10381047 # Only show a marker when there are enough samples
10391048 if all_n >= min_samples :
10401049 marker = ipyleaflet .Marker (
0 commit comments