TST/CLN: remove TestData from frame-tests; replace with fixtures · Issue #22471 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@h-vetinari

Description

@h-vetinari

Following review in #22236:

ok, pls open a new issue that refs this, to remove use of TestData in favor of fixtures

Started the process in that PR by creating a conftest.py that translates all the current attributes of TestData to fixtures, with the following "translation guide":

Need to incrementally replace their usages in pandas/tests/frame/ (example below).

Things for follow-ups:

An example from #22236 - before:

def test_set_columns(self):
    cols = Index(np.arange(len(self.mixed_frame.columns)))
    self.mixed_frame.columns = cols
    with tm.assert_raises_regex(ValueError, 'Length mismatch'):
        self.mixed_frame.columns = cols[::2]

After:

def test_set_columns(self, float_string_frame):
    cols = Index(np.arange(len(float_string_frame.columns)))
    float_string_frame.columns = cols
    with tm.assert_raises_regex(ValueError, 'Length mismatch'):
        float_string_frame.columns = cols[::2]

Basically, it comes down to replacing all the occurrences of self.<name> with translation_guide[<name>] (and specifying<name> as a parameter to the function).

PS. Note that some fixtures added by #22236 have now been removed by #24885. Please check #24885 which code was removed, in case you should need it for the fixturisation. Alternatively, you can ping me, @jbrockmendel or @jreback.