@@ -85,24 +85,28 @@ def _get_pi_dataframe(self, data, pi):
8585 axis = 1 ,
8686 )
8787
88- # Add a row containing sums for certain columns
89- column_sums = []
90- sum_columns_list = []
88+ # Create new row with proper dtypes instead of concatenating with None
89+ # Calculate totals first
90+ column_sums = {}
9191 for column_name in self .TOTAL_COLUMN_LIST :
9292 if column_name in pi_projects .columns :
93- column_sums .append (pi_projects [column_name ].sum ())
94- sum_columns_list .append (column_name )
93+ column_sums [column_name ] = pi_projects [column_name ].sum ()
9594
96- # Add a row with None values (this will convert int64 columns to float64 and bool to object)
97- pi_projects .loc [len (pi_projects )] = None
95+ # Use pandas.concat with future-compatible approach
96+ # Create an empty row first, then populate it
97+ pi_projects = pi_projects .copy () # Ensure we have a copy
98+ new_index = len (pi_projects )
99+
100+ # Add empty row by reindexing
101+ pi_projects = pi_projects .reindex (range (len (pi_projects ) + 1 ))
98102
99103 # Set Invoice Month and totals - add Invoice Month column if it doesn't exist
100104 if invoice .INVOICE_DATE_FIELD not in pi_projects .columns :
101- pi_projects [invoice .INVOICE_DATE_FIELD ] = None
105+ pi_projects [invoice .INVOICE_DATE_FIELD ] = ""
102106
103- pi_projects .loc [pi_projects . index [ - 1 ] , invoice .INVOICE_DATE_FIELD ] = "Total"
104- for col , val in zip ( sum_columns_list , column_sums ):
105- pi_projects .loc [pi_projects . index [ - 1 ] , col ] = val
107+ pi_projects .loc [new_index , invoice .INVOICE_DATE_FIELD ] = "Total"
108+ for col , val in column_sums . items ( ):
109+ pi_projects .loc [new_index , col ] = val
106110
107111 # Add dollar sign to certain columns
108112 for column_name in self .DOLLAR_COLUMN_LIST :
@@ -111,7 +115,14 @@ def _get_pi_dataframe(self, data, pi):
111115 lambda data : data if pandas .isna (data ) else f"${ data } "
112116 )
113117
114- pi_projects .fillna ("" , inplace = True )
118+ # Fill NaN values selectively - only fill non-numeric columns with empty strings
119+ # Keep numeric columns as they are to preserve their dtypes
120+ for col in pi_projects .columns :
121+ if not pandas .api .types .is_numeric_dtype (pi_projects [col ]):
122+ pi_projects [col ] = pi_projects [col ].fillna ("" )
123+
124+ # Convert any remaining pandas NA values to empty strings for template compatibility
125+ pi_projects = pi_projects .fillna ("" )
115126
116127 return pi_projects
117128
0 commit comments