Skip to content
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

TST: Tests and Helpers for Datetime/Period Arrays #23502

Merged
merged 13 commits into from
Nov 9, 2018

Conversation

jbrockmendel
Copy link
Member

Implement ABCDatetimeArray, ABCTimedeltaArray

Fix some problems in DatetimeArray comparison methods, with tests

Implement assert_datetime_array_equal, still need to do the same for TimedeltaArray

Extend fixtures to allow us to run some of the arithmetic tests on PeriodArray, DatetimeArray. Change a few usages to use these fixtures.

This is a companion-PR to #23493. Without that one, we can't easily extend the existing tests. Without this one, problems in the comparison methods would cause failures.

@pep8speaks
Copy link

Hello @jbrockmendel! Thanks for submitting the PR.

pandas/tests/arithmetic/conftest.py Outdated Show resolved Hide resolved
pandas/tests/arrays/test_datetimes.py Outdated Show resolved Hide resolved
@@ -1049,6 +1051,18 @@ def assert_period_array_equal(left, right, obj='PeriodArray'):
assert_attr_equal('freq', left, right, obj=obj)


def assert_datetime_array_equal(left, right, obj='DatetimeArray'):
_check_isinstance(left, right, DatetimeArray)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this needed? why don’t we just have a more generic assert_array_equal

adding more comparison routines generally is just asking for trouble - we already have too many

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we may be able to de-duplicate these once DTA/TDA are EAs, but for now the options are to have this function or to implement something equivalent inside tm.assert_equal

Copy link
Member

Choose a reason for hiding this comment

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

I think it is fine to reconsider this once all internal ExtensionArrays are in place (I think the same was said when adding the assert_period_array_equal that is just above this one)

Copy link
Contributor

Choose a reason for hiding this comment

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

adding more comparison routines generally is just asking for trouble - we already have too many

I really like having separate ones, so that you can assert that you aren't accidentally comparing two of the wrong kind of object. If you just have a generic assert_array_equal you could have built two ndarrays on accident and there's no way to check that the type is correct (unless you pass that as a parameter?)

Copy link
Contributor

Choose a reason for hiding this comment

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

again not sure why this is; the point is we are comparing versus an expected value
so this just extra verbose

eg we recently consolidatednto assert_equal to avoid this exact prome
now adding these back is just more code

sure it’s slightly more explicit but IMHO is not worth the extra functions and maintenance over time

Copy link
Contributor

@TomAugspurger TomAugspurger Nov 7, 2018

Choose a reason for hiding this comment

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

comparing versus an expected value

sometimes though, that expected value isn't constructed explicitly. Sometimes it's the result of some computation (think of the tests in ops for example).

eg we recently consolidatednto assert_equal to avoid this exact prome
now adding these back is just more code

assert_equal just dispatches to each of the specialized asserts. The code has to live somewhere :) But, I don't mean to nitpick over this. I would just rather type

tm.assert_period_array_equal(a, b)

than

tm.assert_array_equal(a, b, kind='period')

or, worse, tm.assert_array_equal(a, b), because I'm lazy, and accidentally not have a period array.

So that's my case, but I'm more than happy to be out voted here :)

Copy link
Contributor

Choose a reason for hiding this comment

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

it’s fine

just want to reduce maintenance burden

@gfyoung gfyoung added Testing pandas testing functions or related to the test suite Datetime Datetime data dtype labels Nov 5, 2018
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Looks good to me in general, some small comments

pandas/core/arrays/datetimes.py Show resolved Hide resolved
pandas/tests/arithmetic/conftest.py Outdated Show resolved Hide resolved
pandas/util/testing.py Outdated Show resolved Hide resolved
@@ -1049,6 +1051,18 @@ def assert_period_array_equal(left, right, obj='PeriodArray'):
assert_attr_equal('freq', left, right, obj=obj)


def assert_datetime_array_equal(left, right, obj='DatetimeArray'):
_check_isinstance(left, right, DatetimeArray)
Copy link
Member

Choose a reason for hiding this comment

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

I think it is fine to reconsider this once all internal ExtensionArrays are in place (I think the same was said when adding the assert_period_array_equal that is just above this one)

@jorisvandenbossche
Copy link
Member

This is a companion-PR to #23493. Without that one, we can't easily extend the existing tests. Without this one, problems in the comparison methods would cause failures.

But do they depend on each other? (meaning, does one need to be merged before the other, or they are orthogonal implementation-wise?)

@jbrockmendel
Copy link
Member Author

But do they depend on each other? (meaning, does one need to be merged before the other, or they are orthogonal implementation-wise?)

They are orthogonal implementation-wise. They are both needed in order to make major progress on sharing existing tests.

@codecov
Copy link

codecov bot commented Nov 7, 2018

Codecov Report

Merging #23502 into master will decrease coverage by <.01%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #23502      +/-   ##
==========================================
- Coverage   92.25%   92.25%   -0.01%     
==========================================
  Files         161      161              
  Lines       51237    51260      +23     
==========================================
+ Hits        47269    47290      +21     
- Misses       3968     3970       +2
Flag Coverage Δ
#multiple 90.63% <93.33%> (ø) ⬆️
#single 42.33% <43.33%> (+0.03%) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/period.py 98.08% <ø> (-0.01%) ⬇️
pandas/core/arrays/datetimelike.py 95.92% <100%> (+0.02%) ⬆️
pandas/core/arrays/timedeltas.py 93.78% <100%> (+0.03%) ⬆️
pandas/util/testing.py 86.78% <100%> (+0.14%) ⬆️
pandas/core/dtypes/generic.py 100% <100%> (ø) ⬆️
pandas/core/arrays/datetimes.py 98.42% <84.61%> (-0.43%) ⬇️

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 ce62a5c...59b7064. Read the comment docs.

@TomAugspurger
Copy link
Contributor

There seemed to be an install error with one of the windows workers. Triggered a rebuild.

@jbrockmendel
Copy link
Member Author

rebuild green

@jbrockmendel
Copy link
Member Author

Travis failure looks wonky and unrelated

@jorisvandenbossche jorisvandenbossche merged commit 5edc439 into pandas-dev:master Nov 9, 2018
@jorisvandenbossche
Copy link
Member

Thanks @jbrockmendel !

@jbrockmendel jbrockmendel deleted the pre-abc branch November 9, 2018 14:09
thoo added a commit to thoo/pandas that referenced this pull request Nov 10, 2018
…fixed

* upstream/master: (47 commits)
  CLN: remove values attribute from datetimelike EAs (pandas-dev#23603)
  DOC/CI: Add linting to rst files, and fix issues (pandas-dev#23381)
  PERF: Speeds up creation of Period, PeriodArray, with Offset freq (pandas-dev#23589)
  PERF: define is_all_dates to shortcut inadvertent copy when slicing an IntervalIndex (pandas-dev#23591)
  TST: Tests and Helpers for Datetime/Period Arrays (pandas-dev#23502)
  Update description of Index._values/values/ndarray_values (pandas-dev#23507)
  Fixes to make validate_docstrings.py not generate warnings or unwanted output (pandas-dev#23552)
  DOC: Added note about groupby excluding Decimal columns by default (pandas-dev#18953)
  ENH: Support writing timestamps with timezones with to_sql (pandas-dev#22654)
  CI: Auto-cancel redundant builds (pandas-dev#23523)
  Preserve EA dtype in DataFrame.stack (pandas-dev#23285)
  TST: Fix dtype mismatch on 32bit in IntervalTree get_indexer test (pandas-dev#23468)
  BUG: raise if invalid freq is passed (pandas-dev#23546)
  remove uses of (ts)?lib.(NaT|iNaT|Timestamp) (pandas-dev#23562)
  BUG: Fix error message for invalid HTML flavor (pandas-dev#23550)
  ENH: Support EAs in Series.unstack (pandas-dev#23284)
  DOC: Updating DataFrame.join docstring (pandas-dev#23471)
  TST: coverage for skipped tests in io/formats/test_to_html.py (pandas-dev#22888)
  BUG: Return KeyError for invalid string key (pandas-dev#23540)
  BUG: DatetimeIndex slicing with boolean Index raises TypeError (pandas-dev#22852)
  ...
JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Nov 14, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants