-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Description
Following review in #22236:
ok, pls open a new issue that refs this, to remove use of
TestDatain 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_frameframe2->float_frame2intframe->int_frametsframe->datetime_framemixed_frame->float_string_framemixed_float->mixed_float_framemixed_float2->mixed_float_frame2mixed_int->mixed_int_frameall_mixed->mixed_type_frametzframe->timezone_frameempty->empty_framets1->datetime_seriests2->datetime_series_shortsimple->simple_frame
Need to incrementally replace their usages in pandas/tests/frame/ (example below).
- Create
conftest.pyand translateTestData-attributes into fixtures (TST/CLN: break up & parametrize tests for df.set_index #22236) -
test_alter_axes.py(TST/CLN: break up & parametrize tests for df.set_index #22236) -
test_analytics.py(TST/CLN: Fixturize frame/test_analytics #22733) -
test_api.py(Fixturize tests/frame/test_api and tests/sparse/frame/test_frame #22738) -
test_apply.py(Fixturize tests/frame/test_apply #22735) -
test_arithmetic.py(Fixturize tests/frame/test_arithmetic #22736) -
test_asof.py(Fixturize tests/frame/test_asof.py #25628) -
test_axis_select_reindex.py(Fixturize tests/frame/test_axis_select_reindex.py #25627) -
test_block_internals.py(TST/CLN: Fixturize tests/frame/test_block_internals.py #22926) -
test_combine_concat.py(Fixturize tests/frame/test_combine_concat.py #25634) -
test_constructors.py(Fixturize tests/frame/test_constructors.py #25635) -
test_convert_to.py -
test_dtypes.py(Fixturize tests/frame/test_dtypes.py #25636) -
test_duplicates.py -
test_indexing.py(Fixturize tests/frame/test_indexing.py #25633) -
test_join.py(Fixturize tests/frame/test_join.py #25639) -
test_missing.py(TST: Fixturize tests/frame/test_missing.py #25640) -
test_mutate_columns.py(Fixturize tests/frame/test_mutate_columns.py #25642) -
test_nonunique_indexes.py -
test_operators.py(Fixturize tests/frame/test_operators.py #25641) -
test_period.py -
test_quantile.py -
test_query_eval.py -
test_rank.py -
test_replace.py -
test_repr_info.py -
test_reshape.py -
test_sort_values_level_as_str.py -
test_sorting.py -
test_subclass.py -
test_timeseries.py -
test_timezones.py -
test_to_csv.py -
test_validate.py
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.