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

Created on 31 Aug 2018  ·  8Comments  ·  Source: pandas-dev/pandas

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).

  • [x] Create conftest.py and translate TestData-attributes into fixtures and renaming them them as outlined above (#22526)
  • [x] test_alter_axes.py (#22526)
  • [x] test_analytics.py (#22755)
  • [x] test_api.py (#29153)
  • [x] test_apply.py (#22769)
  • [x] test_asof.py (#22772)
  • [x] test_combine_concat.py (#22964)
  • [x] test_constructors.py (#22965)
  • [x] test_datetime_values.py (#22966)
  • [x] test_dtypes.py (#22967)
  • [x] test_io.py (#22972)
  • [x] test_missing.py (#22973)
  • [x] test_operators.py (#29084)
  • [x] test_quantile.py (#29096)
  • [x] test_rank.py (#29101)
  • [x] test_replace.py (#29147)
  • [x] test_repr.py (#29148)
  • [x] test_sorting.py (#29149)
  • [x] test_timeseries.py (#29150)
  • [x] test_validate.py (#22756)

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.

Clean Testing good first issue

All 8 comments

Hi! I am looking to start making open source contributions, tests seem like good place to start :)
If no one is working on this, can I take it up?

@Anjali2019, sounds great, but you should wait until #22526 has been merged, otherwise the fixtures in conftest.py will not be available for you.

@h-vetinari Sure! makes sense.

@Anjali2019 good to go. :)
Probably best to start on a per-module basis.

Awesome! Thanks. Will start on it :D

TestData isn't used in the following files which are still marked as open:

  • test_duplicates.py
  • test_internals.py
  • test_period.py
  • test_subclass.py
  • test_timezones.py

I guess you can check the boxes to mark them as done then. ✅

I'll tackle test_operators.py and test_quantile.py next

test_arithmetic.py also doesn't contain TestData, so after merging my pending PRs we can close this issue ✅

I guess the next step then would be to remove the pandas/tests/series/_common.py altogether

I created the follow-up issue to remove _common.py for series tests. This one here can be closed @simonjayhawkins ✌️

EDIT: I'll first need to remove TestData usage in pandas/tests/series/indexing

Was this page helpful?
0 / 5 - 0 ratings