Skip to content

TST: Added regression test #31538

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 30 commits into from
Apr 3, 2020
Merged

Conversation

ShaharNaveh
Copy link
Member

@pep8speaks
Copy link

pep8speaks commented Feb 1, 2020

Hello @MomIsBestFriend! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-03 09:15:17 UTC

@WillAyd WillAyd added the Testing pandas testing functions or related to the test suite label Feb 1, 2020
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

I think a more logical home might be pandas/tests/arrays/test_datetimes.py but @jbrockmendel might have more insight

@jbrockmendel
Copy link
Member

@MomIsBestFriend is moving this to tests.arithmetic something you're up for? (theres lots more that needs attention in that directory, so getting comfortable with the box_with_array pattern there would be worthwhile)

@ShaharNaveh
Copy link
Member Author

ShaharNaveh commented Feb 11, 2020

@jbrockmendel I have to be honest here, I have tried to refactor the test case to use box_with_array, But unfortunately I couldn't make it, just seems odd to me, plus it's kinda lacking a documentation, so it's hard for me to do so, if you have patience I would love if you could guide me a bit on how to do so.

@jbrockmendel
Copy link
Member

I have tried to refactor the test case to use box_with_array, But unfortunately I couldn't make it

I appreciate that you gave it a shot despite the lacking documentation.

The background: until relatively recently, we had separate arithmetic tests for Series/DataFrame/Index, and no systematic way of checking that these all behave the same (and in fact, they didnt). So we've been collecting arithmetic tests in tests.arithmetic and parametrizing over box_with_array (which is roughly just [DataFrame, Series, Index, pd.array]) to ensure that the behavior is internally consistent. As a result, we have a ton of tests there that are either duplicative or not fully parametrized.

The general pattern is to start with a test for just, say, Series:

def test_my_test():
     obj = pd.Series(...)
     other = ...
     expected = pd.Series(...)

     result = op(obj, other)
     tm.assert_series_equal(result, expected)

Parametrizing this over box_with_array would look like:

def test_my_test(box_with_array):
     obj = pd.Series(...)
     other = ...
     expected = pd.Series(...)  # <-- up to here, this can be copy/paste from the other version

     obj = tm.box_expected(obj, box_with_array)
     expected = tm.box_expected(expected, box_with_array)

     result = op(obj, other)
     tm.assert_equal(result, expected)

Does that help?

Note: for exposition this example is implicitly assuming that obj has a datetimelike dtype and that other is a scalar.

@@ -1056,6 +1056,22 @@ def test_dt64arr_add_sub_parr(
)
assert_invalid_addsub_type(dtarr, parr, msg)

def test_timestamp_and_time_dtype_raises(self, box_with_array):
Copy link
Member

Choose a reason for hiding this comment

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

"and" -> "addsub"

)

with pytest.raises(TypeError, match=msg):
obj1 - obj2
Copy link
Member

Choose a reason for hiding this comment

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

the reversed operation obj2 - obj1 should also raise right? How about the addition ops?

@jbrockmendel
Copy link
Member

Can you add a time scalar to the other parametrization in test_dt64arr_add_sub_invalid?

This is looking really good, thanks.

@jreback jreback added this to the 1.1 milestone Mar 3, 2020
@jreback jreback added the Timedelta Timedelta data type label Mar 3, 2020
@jreback
Copy link
Contributor

jreback commented Mar 3, 2020

lgtm. @jbrockmendel if any comments.

@@ -1056,6 +1057,33 @@ def test_dt64arr_add_sub_parr(
)
assert_invalid_addsub_type(dtarr, parr, msg)

def test_timestamp_addsub_time_dtype_raises(self, box_with_array):
Copy link
Member

Choose a reason for hiding this comment

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

"time_dtype" -> "time_objects"?
"timestamp" -> "dt64arr"

@@ -1056,6 +1057,33 @@ def test_dt64arr_add_sub_parr(
)
assert_invalid_addsub_type(dtarr, parr, msg)

def test_timestamp_addsub_time_dtype_raises(self, box_with_array):
Copy link
Member

Choose a reason for hiding this comment

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

tz_naive_fixture


# add
obj1 + obj2
obj2 + obj1
Copy link
Member

Choose a reason for hiding this comment

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

should we be testing that all four of these ops raise TypeError?

Copy link
Member

Choose a reason for hiding this comment

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

Yea this isn't very clear as is whether one or all of these raise a TypeError - can these be split into different contexts?

Copy link
Member

Choose a reason for hiding this comment

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

Or alternately you can parametrize add, radd, sub, rsub

Copy link
Member Author

Choose a reason for hiding this comment

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

Or alternately you can parametrize add, radd, sub, rsub

I can do that, is that's the preferred way?

Copy link
Member

Choose a reason for hiding this comment

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

dealer's choice. i tend not to parametrize over add/radd/sub/rsub since it repeats all the setup code for for what i see as little gain, but on a case-by-case basis if it improves clarity, go for it.


# add
obj1 + obj2
obj2 + obj1
Copy link
Member

Choose a reason for hiding this comment

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

Yea this isn't very clear as is whether one or all of these raise a TypeError - can these be split into different contexts?

@@ -1069,6 +1071,60 @@ def test_dt64arr_add_sub_parr(
)
assert_invalid_addsub_type(dtarr, parr, msg)

def test_dt64arr_addsub_time_object_raises(self, box_with_array, tz_naive_fixture):
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: time_object -> time_objects. otherwise i think this is ready

@jbrockmendel
Copy link
Member

Looks like tests are failing on some paths that go through numexpr

@jreback
Copy link
Contributor

jreback commented Mar 26, 2020

@MomIsBestFriend

can you merge master and see if you can get this to passing

@jbrockmendel
Copy link
Member

LGTM

@jreback jreback merged commit a44ac34 into pandas-dev:master Apr 3, 2020
@jreback
Copy link
Contributor

jreback commented Apr 3, 2020

thanks @MomIsBestFriend

@ShaharNaveh ShaharNaveh deleted the TST-reg-datetime branch April 6, 2020 08:46
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 Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange error message when summing datetime64 and datetime.time column
5 participants