Ideally, there should be one, and only one, obvious place for a test to reside. Until we reach that ideal, these are some rules of thumb for where a test should be located.
Does your test depend only on code in
pd._libs.tslibs? This test likely belongs in one of:
No file in
tests.tslibsshould import from any pandas modules outside of
Does your test depend only on code in pd._libs? This test likely belongs in one of:
Is your test for an arithmetic or comparison method? This test likely belongs in one of:
These are intended for tests that can be shared to test the behavior of DataFrame/Series/Index/ExtensionArray using the
Is your test for a reduction method (min, max, sum, prod, …)? This test likely belongs in one of:
These are intended for tests that can be shared to test the behavior of DataFrame/Series/Index/ExtensionArray.
Is your test for an indexing method? This is the most difficult case for deciding where a test belongs, because there are many of these tests, and many of them test more than one method (e.g. both
Is the test specifically testing an Index method (e.g.
Index.get_indexer)? This test likely belongs in one of:
Within that files there should be a method-specific test class e.g.
In most cases, neither
DataFrameobjects should be needed in these tests.
Is the test for a Series or DataFrame indexing method other than
insert? This test likely belongs in one of:
Is the test for any of
iat? This test likely belongs in one of:
Within the appropriate file, test classes correspond to either types of indexers (e.g.
TestLocBooleanMask) or major use cases (e.g.
See the note in section D) about tests that test multiple indexing methods.
Is the test for
DataFrame.__setitem__? This test likely belongs in one of:
If many cases such a test may test multiple similar methods, e.g.
import pandas as pd import pandas._testing as tm def test_getitem_listlike_of_ints(): ser = pd.Series(range(5)) result = ser[[3, 4]] expected = pd.Series([2, 3]) tm.assert_series_equal(result, expected) result = ser.loc[[3, 4]] tm.assert_series_equal(result, expected)
In cases like this, the test location should be based on the underlying method being tested. Or in the case of a test for a bugfix, the location of the actual bug. So in this example, we know that
Series.loc.__getitem__, so this is really a test for
loc.__getitem__. So this test belongs in
Is your test for a DataFrame or Series method?
Is the method a plotting method? This test likely belongs in one of:
Is the method an IO method? This test likely belongs in one of:
Otherwise This test likely belongs in one of:
If a test can be shared between DataFrame/Series using the
frame_or_seriesfixture, by convention it goes in the
The generic/methods/ directory is only for methods with tests that are fully parametrized over Series/DataFrame
Is your test for an Index method, not depending on Series/DataFrame? This test likely belongs in one of:
Is your test for one of the pandas-provided ExtensionArrays (
StringArray)? This test likely belongs in one of:
Is your test for all ExtensionArray subclasses (the “EA Interface”)? This test likely belongs in one of: