-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STY/TST: what standard to follow to import top-level objects in tests #33203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I prefer the second. |
1st is much better for testing & validation. |
I'm going to refer to the two options as the specific approach and the concise approach, respectively. I've come to prefer the more-specific-imports approach. The test suite is big, and it can be difficult to know "what is tested where?". With specific imports, I can look at the top of a file and rule out a lot of possibilities. This is especially helpful for e.g. Similarly if If |
@jreback Can you explain why? Testing works perfectly fine with both approaches I think.
You can still search for I fully agree that a good and logical organization of the test suite is important, and you are doing a lot of work to clean this up. But personally, I think adding file docstrings explaining the purpose of a file + documentation explaining the general layout of how the tests are organized would be more useful / accessible for other contributors to understand this rather than expecting them to look at imports. @WillAyd reasoning from #29275 (with which I agree):
|
I'm sympathetic to this argument, but if we're going to make copy/paste-ability a criterion, fixtures are a bigger hurdle than imports. |
being more explicit is way better and provides stronger consistency. allowing one to do I don't see any reason to use |
I fully agree on that ;) And we both argumented for that elsewhere. Now, for this specific issue, it's indeed an argument to say that the import is not the most important copy paste issue, but there are still a lot of tests that are not using fixtures (or not for the data being created).
I don't think that any of both approaches is "more explicit" than the other. |
My preference is just importing the module, mainly to make the code explicit. With a silly example, if there is a line That being said, I think in pandas code having |
Consistency in a single module may be more important than following a "foolish" consistency across the whole codebase. However, recently in #32459 there was a similar discussion for imports in cython modules. The outcome seemed to be that the 2nd pattern above was preferred in that context. for me, if there is no clear advantage of one method over the other for testing, I would prefer to adopt the 2nd pattern for consistency. |
So is the agreement to
|
The fewer things are tested in a module, the more I care about specific imports (recall above Im calling the two options "specific"/"concise"). So in @TomAugspurger is this anything like what you meant with your last comment? |
Something like that, though your preferences may be a bit stronger. So the wording may be "prefer specific imports, unless you're testing general things"? |
Yah, strength of preferences in my previous comment should all be normalized by "eh, not that big a deal".
|
xref #23018 as discussion points made on the same topic |
So this discussion regularly comes up (latest one being #33184), so let's try to decide which one of the two we prefer.
In test code, do we do:
or
Personally, I prefer the second, and from recent discussions I have the impression @WillAyd and @datapythonista do as well (is that correct?)
To be clear: consistency within a single file is most important (so not mixing Series and pd.Series in a single file).
But when someone does a PR to fix such inconsistencies in a file, it would be good if there is agreement on whether such a PR should replace
pd.Series
withSeries
or rather replaceSeries
withpd.Series
.The text was updated successfully, but these errors were encountered: