Skip to content

parametrize the first few arithmetic tests #18133

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 14 commits into from
Nov 9, 2017

Conversation

jbrockmendel
Copy link
Member

Start parametrizing arithmetic tests for DatetimeIndex and TimedeltaIndex, with an eye towards re-usability.

Labelling tests with the types of operands and the operations, e.g. "test_dti_add_int" for DatetimeIndex + integer. This make it really easy to tell which combinations are and aren't implemented.

@pep8speaks
Copy link

pep8speaks commented Nov 6, 2017

Hello @jbrockmendel! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on November 09, 2017 at 17:25 Hours UTC

@gfyoung gfyoung added the Testing pandas testing functions or related to the test suite label Nov 6, 2017
idx = DatetimeIndex(['2011-01-01', '2011-01-02'])
msg = "cannot add DatetimeIndex and Timestamp"
with tm.assert_raises_regex(TypeError, msg):
idx + Timestamp('2011-01-01')

def test_dti_radd_timestamp_raises(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually call these errors

tm.assert_index_equal(result, expected)
rng += 1
tm.assert_index_equal(rng, expected)
# Several ways of representing two hours
Copy link
Contributor

Choose a reason for hiding this comment

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

you should make this a fixture

Copy link
Member Author

Choose a reason for hiding this comment

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

Just getting comfortable with pytest.parametrize, will look into fixtures. Mind saving for a follow-up? I want to avoid making the mistake of having multiple active PRs touching the same modules lest rebase-hell ensue. Things Learned The Hard Way, Volume 8.

Copy link
Contributor

Choose a reason for hiding this comment

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

well this ends up add and then removing lots of code
would just like to see it down once

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair enough.


@pytest.mark.parametrize('delta', two_hour_variants)
@pytest.mark.parametrize('tz', tz)
def test_dti_add_timedeltalike(self, tz, delta):
Copy link
Contributor

Choose a reason for hiding this comment

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

then you just add two_hour_variants as an argument (it will work the same way but actually slightly shorter). you ca also make tz a fixture and then the signatures are really simple, e.g. (assume both are fixtures)

def test_dti_add_timedeltalike(self, tz, two_hour_variants): 
....

with test the product of tz x two_hour_variants

@codecov
Copy link

codecov bot commented Nov 6, 2017

Codecov Report

Merging #18133 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18133      +/-   ##
==========================================
- Coverage   91.28%   91.26%   -0.02%     
==========================================
  Files         163      163              
  Lines       50122    50127       +5     
==========================================
- Hits        45752    45749       -3     
- Misses       4370     4378       +8
Flag Coverage Δ
#multiple 89.07% <ø> (ø) ⬆️
#single 40.32% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.75% <0%> (-0.1%) ⬇️
pandas/io/parsers.py 95.58% <0%> (+0.07%) ⬆️

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 1181622...536c160. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 6, 2017

Codecov Report

Merging #18133 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18133      +/-   ##
==========================================
- Coverage   91.42%    91.4%   -0.02%     
==========================================
  Files         163      163              
  Lines       50064    50064              
==========================================
- Hits        45772    45763       -9     
- Misses       4292     4301       +9
Flag Coverage Δ
#multiple 89.21% <ø> (ø) ⬆️
#single 40.36% <ø> (-0.06%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

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 17e0b13...8e4bfa5. Read the comment docs.

@jbrockmendel
Copy link
Member Author

After spending a little time with the docs/examples, I think pytest.fixture is going to stay outside my comfort zone for a while.

@jreback
Copy link
Contributor

jreback commented Nov 8, 2017

look at pandas/tests/reshape/test_merge.py for an example (or pandas/tests/io/tests_parquet.py for more sophisticated usage)

@jbrockmendel
Copy link
Member Author

look at pandas/tests/reshape/test_merge.py for an example

The fixtures there look like they each provide a single DataFrame. We need separate tests for each timezone. Something like:

@pytest.fixture
def tz():
    return [None, 'UTC', 'Asia/Tokyo', 'US/Eastern', 'dateutil/Asia/Singapore',
            'dateutil/US/Pacific']

class Whatever:
     def test_dti_add_timedeltalike(self, tz, delta):

would pass the whole tz fixture as the argument wouldn't it?

@jreback
Copy link
Contributor

jreback commented Nov 9, 2017

“””
@pytest.fixture(params=[None, 'UTC', 'Asia/Tokyo', 'US/Eastern', 'dateutil/Asia/Singapore',
'dateutil/US/Pacific'])
def tz(request):
return request.param
“””

@jbrockmendel
Copy link
Member Author

Too much magic for me, can't implement that with a clear conscience. We've got a good clean win here using pytest.parametrize in more places than before.

@jreback jreback added this to the 0.22.0 milestone Nov 9, 2017
@jreback
Copy link
Contributor

jreback commented Nov 9, 2017

fixed up. pls always rebase when you push on anything.

@jbrockmendel
Copy link
Member Author

Travis error is looks like a DNS fail. Kind of refreshing to not be a Clipboard thing.

@jreback
Copy link
Contributor

jreback commented Nov 9, 2017

i think all mac builds are borked atm

@jbrockmendel
Copy link
Member Author

i think all mac builds are borked atm

Yikes. Just holler if I can do something useful; otherwise I'll stay out of the way.

@jreback jreback merged commit 2f9d4fb into pandas-dev:master Nov 9, 2017
@jreback
Copy link
Contributor

jreback commented Nov 9, 2017

thanks @jbrockmendel

watercrossing pushed a commit to watercrossing/pandas that referenced this pull request Nov 10, 2017
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
@jbrockmendel jbrockmendel deleted the two_hours branch December 8, 2017 19:38
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants