Repository navigation
Bugfix/clean tmpfiles - #206
Conversation
Note that some tempdir may still be present as they are generated through lrh_cache. They should be empty anyway. + blackformatting
|
Thanks for that, should we add |
|
Reading the PR in more details, I'm actually not sure I understand what should be going on here. For instance, you're clearing the tmpdir generated by a function relying on Basically there are three possibilities here:
|
|
Yes you're right. As far as I can see, the tempdir creation is not consistent over the whole package. I'm not sure many tempdirs should be conserved longer than short-term. |
…chema * add context manager around _download_store_file and _load_data_from_schema * rewrite _download_store_file to used predefined tempdir and fix docstring * add a TODO in _download_store_file which does NOT used the update argument * add context manager around file for MD5 checksum Nota: started to refactorize this as in-memory read, but had it revert because of the size of involved files (> 4Go), which would be troublesome on old machines
* rewrite _get_capabilities to return an io.BytesIO object * update _get_full_list_wfs
…t_file_list_internal
|
I think I'm good. As I've said, I removed what seemed to me unnecessary calls to tempfiles. I've kept it on:
I hope there's not too much mistakes on that PR. If there are (which is probably the case), I will be absent for 2 weeks, so feel free to correct it by yourself if needed. EDIT |
|
I've also had some thoughts for future PRs:
If that's ok with you both @hadrilec @tfardet , fill free to open issues on this without me. |
|
Nominatim is called from _get_location_openstreetmap which is, in my opinion, compliant with the guidelines |
I plan on restarting the config PR soon, breaking it into smaller bits this time, this is definitely on my todo list and should indeed go away
good point, we could also add this as a pre-commit hook
OK, I'll check and will open an issue about it if it seems necessary |
Yes about the User Agent (sorry I missed that, I was looking at the session object and didn't even saw you added it on each And also yes about the rate. I've just tested your example from the doc and it queries Nominatim at a rate of 1.4it/sec. Might be something I misunderstood on requests retry system (probably) or even the lagtime to get a query and write it to the disk (which I doubt). I'll have to check what I've missed once I get some time. 😳 |
| df = pd.DataFrame() | ||
| except: | ||
| warnings.warn("Download failed") | ||
| df = pd.DataFrame() |
There was a problem hiding this comment.
@hadrilec I think I overlooked this in the save_df PR, but shouldn't save_df check if the dataframe is empty and not write the file in that case? (if so, I'll open an issue)
There was a problem hiding this comment.
yes you are right, if the dataframe is empty save_df should not write, informing the user with a warning once per py session would be freat
| content = f.read() | ||
|
|
||
| file2load = io.BytesIO(content) | ||
| data = pd.read_csv(file2load, dtype="str", sep=separator) |
There was a problem hiding this comment.
reading CSVs is the slowest thing you can do with pandas... @hadrilec is there a reason why you did not use save_df on this function? If it's a filename concern because it has no arguments, we could add an optional filename argument to save_df to use it there instead, right? (if so I'll make a PR)
There was a problem hiding this comment.
this function downloads csv files from insee.fr, it is called only by the function _download_idbank_list which is using the save_df decorator
|
I will have a look, thanks |
* rm tempdir on _dwn_idbank_file * rm tempfile generated by _get_capabilities * Systemic removal of temp files inside tempdirs Note that some tempdir may still be present as they are generated through lrh_cache. They should be empty anyway. + blackformatting * ignore_errors on shutil.rmtree * Remove unnecessary tempfile * Remove unnecessary tempfile and update idbank ref * Remove unnecessary tempdir from _get_geo_relation * Remove unnecessary tempdir from _get_dataset_dimension * Remove unnecessary tempdir from get_last_release * Remove unnecessary tempdir from _get_insee * Remove unnecessary tempdir from _get_dimension_values * Clean module imports * Remove unnecessary tempdir from _get_geo_list_simple * Remove unnecessary tempdir from _get_dataset_list_internal * Remove unnecessary tempdir from _get_idbank_internal_data * Remove unused module * Add context manager around _download_store_file and _load_data_from_schema * add context manager around _download_store_file and _load_data_from_schema * rewrite _download_store_file to used predefined tempdir and fix docstring * add a TODO in _download_store_file which does NOT used the update argument * add context manager around file for MD5 checksum Nota: started to refactorize this as in-memory read, but had it revert because of the size of involved files (> 4Go), which would be troublesome on old machines * Remove unnecessary tempfile for _get_capabilities * rewrite _get_capabilities to return an io.BytesIO object * update _get_full_list_wfs * Clean up after yourself * Remove unnecessary call to _create_insee_folder and tempfile from _get_file_list_internal * Simplify _create_insee_folder and add a warning on tempfile not beeing cleaned up * Add call to fixed tempdir folder in _import_options * Remove comment Former-commit-id: 94137fb
Should handle that issue #205