145145}
146146
147147
148- def get_all_grants (current_fy : FinancialYear ):
148+ def get_all_grants (current_fy : FinancialYear ) -> pd . DataFrame :
149149 columns = [
150150 "grant_id" ,
151151 "funding_organisation_id" ,
@@ -366,7 +366,7 @@ def grant_table(
366366 columns : list [str ] = DEFAULT_COLUMNS ,
367367 n : int = 100 ,
368368 sortby : str = "-amount_awarded_GBP" ,
369- ):
369+ ) -> pd . DataFrame :
370370 sort_ascending = True
371371 if sortby .startswith ("-" ):
372372 sortby = sortby [1 :]
@@ -382,7 +382,7 @@ def grant_table(
382382def grant_summary (
383383 df : pd .DataFrame ,
384384 groupby : list [str ] = ["category" , "segment" ],
385- ):
385+ ) -> pd . DataFrame :
386386 summary = (
387387 df .groupby (groupby )
388388 .agg (** AGG_COLUMNS )
@@ -448,7 +448,7 @@ def grant_summary(
448448 total_key = tuple ("Total" for k in groupby )
449449 if len (total_key ) == 1 :
450450 total_key = total_key [0 ]
451- summary .loc [total_key , :] = total_row .loc [total_key ]
451+ summary .loc [total_key , :] = total_row .loc [total_key ] # type: ignore
452452
453453 summary = summary .rename (
454454 columns = {
@@ -472,7 +472,7 @@ def grant_crosstab(
472472 groupby : list [str ] = ["category" , "segment" ],
473473 column_field = "amount_awarded_GBP_band" ,
474474 values_field = "grant_id" ,
475- ):
475+ ) -> pd . DataFrame :
476476 aggfunc = "count" if values_field == "grant_id" else "sum"
477477 summary = (
478478 pd .crosstab (
@@ -484,7 +484,7 @@ def grant_crosstab(
484484 .assign (
485485 Total = lambda x : x .sum (axis = 1 ),
486486 )
487- .mask (lambda x : x ["Total" ] == 0 )
487+ .mask (lambda x : x ["Total" ] == 0 ) # type: ignore
488488 .dropna (how = "all" )
489489 )
490490
@@ -515,7 +515,7 @@ def grant_crosstab(
515515 total_key = tuple ("Total" for k in groupby )
516516 if len (total_key ) == 1 :
517517 total_key = total_key [0 ]
518- summary .loc [total_key , :] = total_row .loc [total_key ]
518+ summary .loc [total_key , :] = total_row .loc [total_key ] # type: ignore
519519
520520 if values_field in ("amount_awarded_GBP" , "annual_amount" ):
521521 summary = summary .divide (1_000_000 ).astype (float ).round (1 )
@@ -533,15 +533,15 @@ def grant_by_size(
533533 df : pd .DataFrame ,
534534 groupby : list [str ] = ["category" , "segment" ],
535535 ** kwargs ,
536- ):
536+ ) -> pd . DataFrame :
537537 return grant_crosstab (df , groupby , column_field = "amount_awarded_GBP_band" , ** kwargs )
538538
539539
540540def grant_by_duration (
541541 df : pd .DataFrame ,
542542 groupby : list [str ] = ["category" , "segment" ],
543543 ** kwargs ,
544- ):
544+ ) -> pd . DataFrame :
545545 return grant_crosstab (
546546 df , groupby , column_field = "planned_dates_duration_band" , ** kwargs
547547 )
@@ -551,43 +551,45 @@ def recipient_types(
551551 df : pd .DataFrame ,
552552 groupby : list [str ] = ["category" , "segment" ],
553553 ** kwargs ,
554- ):
554+ ) -> pd . DataFrame :
555555 return grant_crosstab (df , groupby , column_field = "recipient_type" , ** kwargs )
556556
557557
558558def recipients_by_size (
559559 df : pd .DataFrame ,
560560 groupby : list [str ] = ["category" , "segment" ],
561561 ** kwargs ,
562- ):
562+ ) -> pd . DataFrame :
563563 return grant_crosstab (df , groupby , column_field = "recipient_income_band" , ** kwargs )
564564
565565
566566def recipients_by_scale (
567567 df : pd .DataFrame ,
568568 groupby : list [str ] = ["category" , "segment" ],
569569 ** kwargs ,
570- ):
570+ ) -> pd . DataFrame :
571571 return grant_crosstab (df , groupby , column_field = "recipient__scale" , ** kwargs )
572572
573573
574574def grants_by_region (
575575 df : pd .DataFrame ,
576576 groupby : list [str ] = ["category" , "segment" ],
577577 ** kwargs ,
578- ):
578+ ) -> pd . DataFrame :
579579 return grant_crosstab (df , groupby , column_field = "region" , ** kwargs )
580580
581581
582582def grants_by_country (
583583 df : pd .DataFrame ,
584584 groupby : list [str ] = ["category" , "segment" ],
585585 ** kwargs ,
586- ):
586+ ) -> pd . DataFrame :
587587 return grant_crosstab (df , groupby , column_field = "country" , ** kwargs )
588588
589589
590- def explode_crosstab (df : pd .DataFrame , groupby : list [str ], field : str , ** kwargs ):
590+ def explode_crosstab (
591+ df : pd .DataFrame , groupby : list [str ], field : str , ** kwargs
592+ ) -> pd .DataFrame :
591593 ct = grant_crosstab (
592594 df [df [field ].notnull ()].explode (field ).reset_index (),
593595 groupby ,
@@ -608,7 +610,7 @@ def grants_by_who(
608610 df : pd .DataFrame ,
609611 groupby : list [str ] = ["category" , "segment" ],
610612 ** kwargs ,
611- ):
613+ ) -> pd . DataFrame :
612614 field = "recipient__who"
613615 return explode_crosstab (
614616 df ,
@@ -622,7 +624,7 @@ def grants_by_how(
622624 df : pd .DataFrame ,
623625 groupby : list [str ] = ["category" , "segment" ],
624626 ** kwargs ,
625- ):
627+ ) -> pd . DataFrame :
626628 field = "recipient__how"
627629 return explode_crosstab (
628630 df ,
@@ -636,7 +638,7 @@ def grants_by_what(
636638 df : pd .DataFrame ,
637639 groupby : list [str ] = ["category" , "segment" ],
638640 ** kwargs ,
639- ):
641+ ) -> pd . DataFrame :
640642 field = "recipient__what"
641643 return explode_crosstab (
642644 df ,
@@ -646,7 +648,7 @@ def grants_by_what(
646648 )
647649
648650
649- def recipient_size_by_amount_awarded (df : pd .DataFrame , ** kwargs ):
651+ def recipient_size_by_amount_awarded (df : pd .DataFrame , ** kwargs ) -> pd . DataFrame :
650652 return grant_crosstab (
651653 df ,
652654 ["amount_awarded_GBP_band" ],
@@ -655,7 +657,7 @@ def recipient_size_by_amount_awarded(df: pd.DataFrame, **kwargs):
655657 )
656658
657659
658- def number_of_grants_by_recipient (df : pd .DataFrame ):
660+ def number_of_grants_by_recipient (df : pd .DataFrame ) -> pd . DataFrame :
659661 summary = (
660662 df .groupby ("recipient_id" )
661663 .agg (
@@ -698,7 +700,7 @@ def number_of_grants_by_recipient(df: pd.DataFrame):
698700 return summary
699701
700702
701- def who_funds_with_who (df : pd .DataFrame , groupby : str = "segment" ):
703+ def who_funds_with_who (df : pd .DataFrame , groupby : str = "segment" ) -> pd . DataFrame :
702704 wfww = pd .crosstab (
703705 df ["recipient_id" ],
704706 df [groupby ],
0 commit comments