Skip to content

TST: add tests for period resample sum with min_count #29762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ganevgv
Copy link
Contributor

@ganevgv ganevgv commented Nov 21, 2019

@@ -694,6 +694,20 @@ def test_resample_timestamp_to_period(simple_date_range_series):
tm.assert_series_equal(result, expected)


def test_datetime_resample_sum_min_count():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this to the base class where its tests all of DTI, PI, TDI; pls use the fixtures.

@jreback jreback added Resample resample method Testing pandas testing functions or related to the test suite labels Nov 22, 2019
@jreback jreback added this to the 1.0 milestone Nov 22, 2019
@@ -694,6 +694,20 @@ def test_resample_timestamp_to_period(simple_date_range_series):
tm.assert_series_equal(result, expected)


def test_datetime_resample_sum_min_count():
# GH 19974
index = date_range(start="2018", freq="M", periods=6)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not actually testing for the issue as this is a DTI and not a PI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this test was using DTI as that was referenced as the expected behaviour in the issue.
Not it's removed and the only test left is using PI - test_period_resample_sum_min_count in pandas/tests/resample/test_period_index.py.

@ganevgv ganevgv changed the title TST: add tests for period/datetime resample sum with min_count TST: add tests for period resample sum with min_count Nov 23, 2019
@ganevgv ganevgv requested a review from jreback November 23, 2019 17:41
@@ -548,6 +548,19 @@ def test_quarterly_resampling(self):
exp = ts.to_timestamp().resample("A").mean().to_period()
tm.assert_series_equal(result, exp)

def test_period_resample_sum_min_count(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this test be done more generally in test_base?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback @jreback - moved the test and generalised to include tests for DTI, PI and TDI.

@ganevgv ganevgv requested a review from jreback November 30, 2019 01:24
series[:5] = 1
series[5:] = np.nan

if isinstance(series.index, TimedeltaIndex) and freq != "D":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this particular case in the test_timedelta.py as its only relevant there and makes the test setup way too complicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense - moved the tdi test to test_timedelta.py


if isinstance(series.index, DatetimeIndex) and result_name == "dti":
index = DatetimeIndex(result_index, freq=result_freq)
expected = Series(result_data, index, name=result_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are duplicating a lot of code here, pls share

expected = Series(result_data, index, name=result_name)
tm.assert_series_equal(result, expected)

if isinstance(series.index, PeriodIndex) and result_name == "pi":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing this you can simply add a 'box' argument that does the appropriate conversion in the cases

e.g.

for 'pi'

PeriodIndex

and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the feedback @jreback - changed the test so that there's no duplication anymore

@ganevgv ganevgv requested a review from jreback December 6, 2019 19:54
@pytest.mark.parametrize(
"_index_factory,_series_name,_index_start,_index_end", [DATE_RANGE, PERIOD_RANGE]
)
@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ganevgv rather than nesting a dict, just make data, index paramters e.g.

@pytest.mark.parameterize('freq, data, index')

otherwise this is very hard to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback - removed the nested dict and changed the format to:

@pytest.mark.parameterize("freq, result_name, result_data, result_index, result_freq")

@ganevgv ganevgv force-pushed the tests/datetime_resample_sum_min_count branch from 3fc7c4b to f7c1515 Compare December 16, 2019 16:34
@ganevgv ganevgv requested a review from jreback December 16, 2019 18:38
@jreback
Copy link
Contributor

jreback commented Dec 27, 2019

can you merge master and will look again

@jreback jreback removed this from the 1.0 milestone Jan 1, 2020
@ganevgv ganevgv force-pushed the tests/datetime_resample_sum_min_count branch from f7c1515 to 3d6bfa3 Compare January 2, 2020 13:38
@ganevgv
Copy link
Contributor Author

ganevgv commented Jan 2, 2020

@jreback - rebased onto latest master.

@alimcmaster1
Copy link
Member

@ganevgv - sorry can you merge master again - there are some conflicts

@simonjayhawkins
Copy link
Member

superseded by #31196

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resample resample method Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

min_count is ignored by sum/prod when resampling a PeriodIndex
4 participants