Skip to content

TST: fixtures for timezones #20365

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

Merged
merged 1 commit into from
Apr 12, 2018
Merged

Conversation

almaleksia
Copy link
Contributor

This is a follow up for #20287

Different tests use different lists of timezones and it's kind of hard to unify all of them. In this PR I tried to create a fixture that covers most frequent cases. Some tests use naive timezone, while others are designed to use only explicit timezones (and fail in case tz is not specified), that's why I created two fixtures to cover these two group of tests. List of timezones also includes one dateutil-timezone.
I'm not sure if described approach is correct though so I would appreciate any feedback.

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

@jreback jreback added the Testing pandas testing functions or related to the test suite label Mar 15, 2018
@pytest.fixture(params=TIMEZONES)
def tz_naive(request):
"""
Fixture for trying timezones including default (None)
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 make this ore explicit (e.g. list the timezones here); you can programatically construct the doc string I think (to make this DRY)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added decorator for this

@pytest.fixture(params=TIMEZONES[1::])
def tz_aware(request):
"""
Fixture for trying explicit timezones
Copy link
Contributor

Choose a reason for hiding this comment

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

same



@pytest.fixture(params=TIMEZONES)
def tz_naive(request):
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't be averse to making the name of this slightly more explict

maybe tz_naive_fixture (maybe we should do this with the other fixtures as well, can be separate PR for that change)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done :)

@pytest.fixture(params=[None, 'UTC', 'Asia/Tokyo', 'US/Eastern',
'dateutil/Asia/Singapore',
'dateutil/US/Pacific'])
def tz(request):
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe tz_fixture

idx2 = DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
'2011-01-01 11:00'], freq='H',
tz='Asia/Tokyo', name='tzidx')
@pytest.mark.parametrize('idx',
Copy link
Contributor

Choose a reason for hiding this comment

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

you can format this more like

@pytest.mark.parameterize(
   'idx',
       [
         DatetimeIndex(......),
         DatetimeIndex(....)')

e.g. to fit more on a line

@jreback jreback added the Timezones Timezone data dtype label Mar 15, 2018
@jreback
Copy link
Contributor

jreback commented Mar 15, 2018

@jbrockmendel ?

@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

Merging #20365 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20365      +/-   ##
==========================================
- Coverage   91.84%   91.82%   -0.03%     
==========================================
  Files         152      152              
  Lines       49264    49269       +5     
==========================================
- Hits        45246    45239       -7     
- Misses       4018     4030      +12
Flag Coverage Δ
#multiple 90.2% <100%> (-0.03%) ⬇️
#single 41.91% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/_test_decorators.py 92.4% <100%> (+0.51%) ⬆️
pandas/plotting/_converter.py 65.07% <0%> (-1.74%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a77ac2b...2573948. Read the comment docs.

@jbrockmendel
Copy link
Member

A few thoughts, in no particular order:

  • Generally looks quite nice. @almaleksia thanks for putting this together.
  • I'm a bit concerned about always using the same ~4 timezones. Is there a risk of some special case weirdness in other timezones that we're missing?
  • Would there be a use for separate fixtures for tzstr for tzinfo objects?

return request.param


@pytest.fixture(params=TIMEZONES[1::])
Copy link
Member

Choose a reason for hiding this comment

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

Is a single-colon OK here?

@almaleksia
Copy link
Contributor Author

@jreback @jbrockmendel
thank you for the feedback!

I'm a bit concerned about always using the same ~4 timezones. Is there a risk of some special case weirdness in other timezones that we're missing?

Actually I had the same thought. As for this change, it affects only tests that already share similar list of timezones. I made sure that I didn't shorten or replace timezone lists used in the existing tests. Let's say test is using some timezone not covered by the fixture then list is not replaced. Several tests though got extended by one timezone (dateutil/US/Pacific) after being moved to the fixture. I thought about adding more timezones to the list but for some tests it looked a bit redundant, so I decided to save some build time.

Would there be a use for separate fixtures for tzstr for tzinfo objects?

do you mean tests like in test_timezones parametrized with tzstr?

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Mar 16, 2018

I thought about adding more timezones to the list but for some tests it looked a bit redundant, so I decided to save some build time.

I think that's the right choice. This would be a decent case for using hypothesis: #17978 (but that's for another issue)

@@ -187,3 +187,10 @@ def decorated_func(func):
"installed->{installed}".format(
enabled=_USE_NUMEXPR,
installed=_NUMEXPR_INSTALLED))


def parametrize_fixture_doc(*args):
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 nice, in a future PR can you document this itself?

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 add docs on this here

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 done
sorry didn't see this comment at first, so I did two updates (one for rebase and one for doc), I think previous builds can be cancelled

@jreback jreback added this to the 0.23.0 milestone Apr 1, 2018
@jreback
Copy link
Contributor

jreback commented Apr 1, 2018

can you rebase this just to make sure

@TomAugspurger TomAugspurger merged commit fa231e8 into pandas-dev:master Apr 12, 2018
@TomAugspurger
Copy link
Contributor

Thanks @almaleksia!

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

Successfully merging this pull request may close these issues.

4 participants