Skip to content

perf: cast dates with the format inferred by csv-detective - #470

Open
ThibaudDauce wants to merge 6 commits into
mainfrom
feat/use-inferred-date-format
Open

perf: cast dates with the format inferred by csv-detective#470
ThibaudDauce wants to merge 6 commits into
mainfrom
feat/use-inferred-date-format

Conversation

@ThibaudDauce

Copy link
Copy Markdown
Contributor

Use the new date_format added in datagouv/csv-detective#245

Fichier inspection csv to db total
main branche Δ main branche Δ main branche Δ
ValeursFoncieres-2024.txt 44,2 44,3 +0 % 50,1 31,6 −37 % 94,3 75,9 −20 %
ValeursFoncieres-2025-S1.txt 16,4 16,5 +0 % 20,2 12,7 −37 % 36,7 29,2 −20 %
MN_07 (sans date) 30,5 28,9 −5 % 9,9 10,1 +2 % 40,3 39,0 −3 %
joconde.csv 106,8 104,2 −2 % 22,6 18,5 −18 % 129,4 122,8 −5 %
irve.csv 7,9 6,7 −15 % 12,6 5,7 −55 % 20,6 12,4 −40 %

@bolinocroustibat
bolinocroustibat self-requested a review August 19, 2026 12:53

@bolinocroustibat bolinocroustibat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few remarks, an important one is to keep the explicit csv-detective version in pyproject (and make a release of csv-detective if necessary).

Comment thread pyproject.toml
"asyncpg>=0.29.0",
"coloredlogs>=15.0.1",
"csv-detective==0.12.0",
"csv-detective",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not unpin the csv detective version in pyproject, since it's a base component of hydra we need to track and pin the version explicitly by bumping it manually. The manual version change in the pyproject file is an established process in the repo and a good way to protect from human errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be reverted as soon as the new version is released (this hydra branch require the new csv-detective of datagouv/csv-detective#245)

@bolinocroustibat bolinocroustibat Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not merge this branch before there is a version of csv-detective released for that!

Comment thread pyproject.toml
[tool.uv]
constraint-dependencies = ["urllib3>=2.7.0"]

# `cast()` only takes the inferred date format from that branch on. Pin it back to a released

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to add that kind of shim to the version control which decreases readability, maintainability and not as explicit ad the version in pyproject.
Better to create a release of csv-detective and pin the version of the module in pyproject so that it's very explicit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, this PR require the new version of csv-detective and cannot be merge without it… This comment is just here to remind us to change this, no?

@bolinocroustibat bolinocroustibat Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not merge this branch before there is a version of csv-detective released for that!

@pytest.mark.parametrize(
"values_expected",
(
# a value no other value of the column disambiguates is read day-first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the date format YYYY/MM/DD? Is it supported by csv-detective? In any case, should we test it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is supposed to be supported ! As well as YYYY/DD/MM

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree we should test it

Comment thread udata_hydra/utils/casting.py Outdated
failsafe=False,
)
for _type, value in zip(columns.values(), line)
for (_type, date_format), value in zip(columns.values(), line)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is becoming a bit difficult to read so I changed for a more explicit (and performant) unpacking: bb5d991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants