Skip to content

TST: add error message match for raise in test_datetimelike.py GH30999 #37952

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 3 commits into from
Nov 20, 2020

Conversation

liaoaoyuan97
Copy link
Contributor

@liaoaoyuan97 liaoaoyuan97 commented Nov 19, 2020

Reference #30999

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

f"or array of those. Got '{type(string).__name__}' instead."
),
):
arr.searchsorted(string)
Copy link
Member

Choose a reason for hiding this comment

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

can this (and line 325) be kept as they originally were?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MarcoGorelli I see the point to keep it as original here. For line325, is it because extract_array() may change later and break the test? And in contract, StringArray (type name) is less likely to change.

Copy link
Member

Choose a reason for hiding this comment

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

It's not too important admittedly, it's just to minimise the amount of logic in tests as any assignment / substitution / branch has the potential to introduce bugs. When we write source code we want to write helper functions and not repeat ourselves and all of that, but for tests repetition is more acceptable - see https://testing.googleblog.com/2014/07/testing-on-toilet-dont-put-logic-in.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. The article is very helpful. Thanks a lot!

Comment on lines 310 to 311
f"value should be a '{arr1d._scalar_type.__name__}', 'NaT', "
f"or array of those. Got '{type(string).__name__}' instead."
Copy link
Member

Choose a reason for hiding this comment

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

match takes a regular expression, which is checked using re.search. So the .s will match any character - can you use match=re.escape( instead of match=?

@jreback jreback added Testing pandas testing functions or related to the test suite Error Reporting Incorrect or improved errors from pandas labels Nov 19, 2020
@jreback jreback added this to the 1.2 milestone Nov 20, 2020
@jreback
Copy link
Contributor

jreback commented Nov 20, 2020

lgtm. @MarcoGorelli merge when ready.

@MarcoGorelli MarcoGorelli merged commit 1268cd3 into pandas-dev:master Nov 20, 2020
@MarcoGorelli
Copy link
Member

Thanks @liaoaoyuan97 !

@liaoaoyuan97 liaoaoyuan97 deleted the test_datetimelike branch November 20, 2020 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants