Skip to content

Commit 0b84479

Browse files
committed
import_geiq: force SIRET type to integer
When replacing NaN elements with None, if the siret column is not explicitely defined as integer, it is converted to float. These values later converted to string, need to be integers, otherwise they are suffixed with `.0`.
1 parent 9cc8548 commit 0b84479

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

itou/companies/management/commands/import_geiq.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def get_geiq_df(filename):
3434
}
3535
df = remap_columns(df, column_mapping=column_mapping)
3636

37+
# Force siret type to integer, otherwise replacing NaN elements to None blindly converts them to float.
38+
df["siret"] = df["siret"].astype("Int64")
39+
3740
# Replace NaN elements with None.
3841
df = df.replace({np.nan: None})
3942

tests/companies/test_management_command_import_geiq.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ def test_get_geiq_df(sftp_directory, faker):
132132
with pytest.raises(AssertionError):
133133
df, info_stats = get_geiq_df(file_path)
134134

135+
# Missing some sirets
136+
rows = 185
137+
rows_with_empty_siret = 20
138+
rows_with_empty_email = 0
139+
data = generate_data(
140+
rows=rows, rows_with_empty_siret=rows_with_empty_siret, rows_with_empty_email=rows_with_empty_email
141+
)
142+
file_path = sftp_directory.joinpath(faker.geiq_filename())
143+
with open(file_path, "wb") as xlsxfile:
144+
workbook = generate_excel_sheet(FILE_HEADERS, data)
145+
workbook.save(xlsxfile)
146+
df, info_stats = get_geiq_df(file_path)
147+
assert df.shape == (rows - rows_with_empty_siret, 8)
148+
assert info_stats == {
149+
"rows_in_file": rows,
150+
"rows_with_a_siret": rows - rows_with_empty_siret,
151+
"rows_after_deduplication": rows - rows_with_empty_siret,
152+
"rows_with_empty_email": 0,
153+
}
154+
135155
# Duplicated rows
136156
rows = 250
137157
rows_with_empty_siret = 0

0 commit comments

Comments
 (0)