Skip to content

TST/CLN: remove TestData from series-tests; replace with fixtures #22550

@h-vetinari

Description

@h-vetinari

This is the sister-issue for Series of #22471 (for frames), where the review in #22236 requested:

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

For Series, this process is started by #22526 by creating a conftest.py that translates all the current attributes of TestData to fixtures, with the following "translation guide":

  • ts -> datetime_series
  • series -> string_series
  • objSeries -> object_series
  • empty -> empty_series

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

Things for follow-ups:

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

An example from #22526 - before:

def test_rename_inplace(self):
    renamer = lambda x: x.strftime('%Y%m%d')
    expected = renamer(self.ts.index[0])
    self.ts.rename(renamer, inplace=True)
    assert self.ts.index[0] == expected

After:

def test_rename_inplace(self, datetime_series):
    renamer = lambda x: x.strftime('%Y%m%d')
    expected = renamer(datetime_series.index[0])
    datetime_series.rename(renamer, inplace=True)
    assert datetime_series.index[0] == expected

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

PS. Note that some fixtures added by #22526 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

    CleanTestingpandas testing functions or related to the test suite

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions