Skip to content

TST/CLN: remove TestData from frame-tests; replace with fixtures #22471

Closed
@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":

  • frame -> float_frame
  • frame2 -> float_frame2
  • intframe -> int_frame
  • tsframe -> datetime_frame
  • mixed_frame -> float_string_frame
  • mixed_float -> mixed_float_frame
  • mixed_float2 -> mixed_float_frame2
  • mixed_int -> mixed_int_frame
  • all_mixed -> mixed_type_frame
  • tzframe -> timezone_frame
  • empty -> empty_frame
  • ts1 -> datetime_series
  • ts2 -> datetime_series_short
  • simple -> simple_frame

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

Things for follow-ups:

  • Remove other class-based test-methods
  • Turn tests from class- to function-based

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions