Skip to content

MAINT: lib: Some code clean up in loadtxt - #16633

Merged
mattip merged 4 commits into
numpy:masterfrom
WarrenWeckesser:maint-loadtxt
Jun 18, 2020
Merged

mattip merged 4 commits into
numpy:masterfrom
WarrenWeckesser:maint-loadtxt

Conversation

@WarrenWeckesser

Copy link
Copy Markdown
Member

This is a maintenance-only PR, in preparation for some bug fixes and enhancements.

This change moves the nested function definitions in loadtxt
to the top of the function body.
Validation of `ndmin` is moved to the beginning of the function,
so we don't read the entire file only to raise an exception at
the end because of a bad argument.
In loadtxt, there is a try/finally block that ensures that the file
is closed if it was opened in the function.  Some code that did not
need to be in that block was moved up, outside the try/finally block.
@WarrenWeckesser

WarrenWeckesser commented Jun 18, 2020 •

Copy link
Copy Markdown
Member Author

I was tempted to move the nested functions flatten_dtype_internal and pack_items out of the loadtxt definition, and make them private functions at the top level of the module. Having them nested in loadtxt is unnecessary. They are standalone functions, with no need to be exposed to the scope of loadtxt. If anyone agrees such a change is worthwhile, I'll add it to this PR.

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks for splitting into separate commits too!

@WarrenWeckesser

Copy link
Copy Markdown
Member Author

The one failure on TravisCI is the s390x platform, where the log has
just one line:

An error occurred while generating the build script.

@mattip
mattip merged commit b3f7132 into numpy:master Jun 18, 2020
@mattip

mattip commented Jun 18, 2020

Copy link
Copy Markdown
Member

Thanks @WarrenWeckesser

@WarrenWeckesser
WarrenWeckesser deleted the maint-loadtxt branch June 18, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants