-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
TST: Tests and Helpers for Datetime/Period Arrays #23502
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
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
083135d
Implement ABCDatetimeArray, ABCTimedeltaArray
jbrockmendel b282e8f
Add tests
jbrockmendel 1e56627
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel 5e1b3ef
isort
jbrockmendel d1188ac
flake8 fixup
jbrockmendel caedb95
parametrize test
jbrockmendel 5a02923
longer names for fixtures
jbrockmendel cd060d1
isort imports
jbrockmendel baad2af
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel 87070a2
update fixture name, add dtypes.generic tests
jbrockmendel 72a849b
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel 03f5208
Merge branch 'master' of https://github.com/pandas-dev/pandas into pr…
jbrockmendel 59b7064
remove extra equality check
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Tests for DatetimeArray | ||
""" | ||
import operator | ||
|
||
import numpy as np | ||
|
||
import pandas as pd | ||
from pandas.core.arrays import DatetimeArrayMixin as DatetimeArray | ||
import pandas.util.testing as tm | ||
|
||
|
||
class TestDatetimeArrayComparisons(object): | ||
# TODO: merge this into tests/arithmetic/test_datetime64 once it is | ||
# sufficiently robust | ||
|
||
def test_cmp_dt64_arraylike_tznaive(self, all_compare_operators): | ||
# arbitrary tz-naive DatetimeIndex | ||
opname = all_compare_operators.strip('_') | ||
op = getattr(operator, opname) | ||
|
||
dti = pd.date_range('2016-01-1', freq='MS', periods=9, tz=None) | ||
arr = DatetimeArray(dti) | ||
assert arr.freq == dti.freq | ||
assert arr.tz == dti.tz | ||
|
||
right = dti | ||
|
||
expected = np.ones(len(arr), dtype=bool) | ||
if opname in ['ne', 'gt', 'lt']: | ||
# for these the comparisons should be all-False | ||
expected = ~expected | ||
|
||
result = op(arr, arr) | ||
tm.assert_numpy_array_equal(result, expected) | ||
for other in [right, np.array(right)]: | ||
# TODO: add list and tuple, and object-dtype once those | ||
# are fixed in the constructor | ||
result = op(arr, other) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
result = op(other, arr) | ||
tm.assert_numpy_array_equal(result, expected) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ | |
IntervalIndex, MultiIndex, Panel, PeriodIndex, RangeIndex, Series, | ||
TimedeltaIndex, bdate_range) | ||
from pandas.core.algorithms import take_1d | ||
from pandas.core.arrays import ExtensionArray, IntervalArray, PeriodArray | ||
from pandas.core.arrays import ( | ||
DatetimeArrayMixin as DatetimeArray, ExtensionArray, IntervalArray, | ||
PeriodArray, period_array) | ||
import pandas.core.common as com | ||
|
||
from pandas.io.common import urlopen | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
assert_numpy_array_equal(left._data, right._data, | ||
obj='{obj}._data'.format(obj=obj)) | ||
assert_attr_equal('freq', left, right, obj=obj) | ||
assert_attr_equal('tz', left, right, obj=obj) | ||
|
||
# Check that == works as expected | ||
assert ((left == right) | (left._isnan & right._isnan)).all() | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def raise_assert_detail(obj, message, left, right, diff=None): | ||
__tracebackhide__ = True | ||
|
||
|
@@ -1546,6 +1560,8 @@ def assert_equal(left, right, **kwargs): | |
assert_interval_array_equal(left, right, **kwargs) | ||
elif isinstance(left, PeriodArray): | ||
assert_period_array_equal(left, right, **kwargs) | ||
elif isinstance(left, DatetimeArray): | ||
assert_datetime_array_equal(left, right, **kwargs) | ||
elif isinstance(left, ExtensionArray): | ||
assert_extension_array_equal(left, right, **kwargs) | ||
elif isinstance(left, np.ndarray): | ||
|
@@ -1573,6 +1589,11 @@ def box_expected(expected, box_cls): | |
expected = pd.Series(expected) | ||
elif box_cls is pd.DataFrame: | ||
expected = pd.Series(expected).to_frame() | ||
elif box_cls is PeriodArray: | ||
# the PeriodArray constructor is not as flexible as period_array | ||
expected = period_array(expected) | ||
elif box_cls is DatetimeArray: | ||
expected = DatetimeArray(expected) | ||
elif box_cls is np.ndarray: | ||
expected = np.array(expected) | ||
else: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.