-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TST: Parametrize dtypes tests - test_common.py and test_concat.py #20340
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pandas as pd | ||
import pytest | ||
import pandas.core.dtypes.concat as _concat | ||
|
||
|
||
class TestConcatCompat(object): | ||
|
||
def check_concat(self, to_concat, exp): | ||
for klass in [pd.Index, pd.Series]: | ||
to_concat_klass = [klass(c) for c in to_concat] | ||
res = _concat.get_dtype_kinds(to_concat_klass) | ||
assert res == set(exp) | ||
|
||
def test_get_dtype_kinds(self): | ||
to_concat = [['a'], [1, 2]] | ||
self.check_concat(to_concat, ['i', 'object']) | ||
|
||
to_concat = [[3, 4], [1, 2]] | ||
self.check_concat(to_concat, ['i']) | ||
|
||
to_concat = [[3, 4], [1, 2.1]] | ||
self.check_concat(to_concat, ['i', 'f']) | ||
|
||
def test_get_dtype_kinds_datetimelike(self): | ||
to_concat = [pd.DatetimeIndex(['2011-01-01']), | ||
pd.DatetimeIndex(['2011-01-02'])] | ||
self.check_concat(to_concat, ['datetime']) | ||
|
||
to_concat = [pd.TimedeltaIndex(['1 days']), | ||
pd.TimedeltaIndex(['2 days'])] | ||
self.check_concat(to_concat, ['timedelta']) | ||
|
||
def test_get_dtype_kinds_datetimelike_object(self): | ||
to_concat = [pd.DatetimeIndex(['2011-01-01']), | ||
pd.DatetimeIndex(['2011-01-02'], tz='US/Eastern')] | ||
self.check_concat(to_concat, | ||
['datetime', 'datetime64[ns, US/Eastern]']) | ||
|
||
to_concat = [pd.DatetimeIndex(['2011-01-01'], tz='Asia/Tokyo'), | ||
pd.DatetimeIndex(['2011-01-02'], tz='US/Eastern')] | ||
self.check_concat(to_concat, | ||
['datetime64[ns, Asia/Tokyo]', | ||
'datetime64[ns, US/Eastern]']) | ||
|
||
# timedelta has single type | ||
to_concat = [pd.TimedeltaIndex(['1 days']), | ||
pd.TimedeltaIndex(['2 hours'])] | ||
self.check_concat(to_concat, ['timedelta']) | ||
|
||
to_concat = [pd.DatetimeIndex(['2011-01-01'], tz='Asia/Tokyo'), | ||
pd.TimedeltaIndex(['1 days'])] | ||
self.check_concat(to_concat, | ||
['datetime64[ns, Asia/Tokyo]', 'timedelta']) | ||
|
||
def test_get_dtype_kinds_period(self): | ||
# because we don't have Period dtype (yet), | ||
# Series results in object dtype | ||
to_concat = [pd.PeriodIndex(['2011-01'], freq='M'), | ||
pd.PeriodIndex(['2011-01'], freq='M')] | ||
res = _concat.get_dtype_kinds(to_concat) | ||
assert res == set(['period[M]']) | ||
|
||
to_concat = [pd.Series([pd.Period('2011-01', freq='M')]), | ||
pd.Series([pd.Period('2011-02', freq='M')])] | ||
res = _concat.get_dtype_kinds(to_concat) | ||
assert res == set(['object']) | ||
|
||
to_concat = [pd.PeriodIndex(['2011-01'], freq='M'), | ||
pd.PeriodIndex(['2011-01'], freq='D')] | ||
res = _concat.get_dtype_kinds(to_concat) | ||
assert res == set(['period[M]', 'period[D]']) | ||
|
||
to_concat = [pd.Series([pd.Period('2011-01', freq='M')]), | ||
pd.Series([pd.Period('2011-02', freq='D')])] | ||
res = _concat.get_dtype_kinds(to_concat) | ||
assert res == set(['object']) | ||
from pandas import ( | ||
Index, DatetimeIndex, PeriodIndex, TimedeltaIndex, Series, Period) | ||
|
||
|
||
@pytest.mark.parametrize('to_concat, expected', [ | ||
# int/float/str | ||
([['a'], [1, 2]], ['i', 'object']), | ||
([[3, 4], [1, 2]], ['i']), | ||
([[3, 4], [1, 2.1]], ['i', 'f']), | ||
|
||
# datetimelike | ||
([DatetimeIndex(['2011-01-01']), DatetimeIndex(['2011-01-02'])], | ||
['datetime']), | ||
([TimedeltaIndex(['1 days']), TimedeltaIndex(['2 days'])], | ||
['timedelta']), | ||
|
||
# datetimelike object | ||
([DatetimeIndex(['2011-01-01']), | ||
DatetimeIndex(['2011-01-02'], tz='US/Eastern')], | ||
['datetime', 'datetime64[ns, US/Eastern]']), | ||
([DatetimeIndex(['2011-01-01'], tz='Asia/Tokyo'), | ||
DatetimeIndex(['2011-01-02'], tz='US/Eastern')], | ||
['datetime64[ns, Asia/Tokyo]', 'datetime64[ns, US/Eastern]']), | ||
([TimedeltaIndex(['1 days']), TimedeltaIndex(['2 hours'])], | ||
['timedelta']), | ||
([DatetimeIndex(['2011-01-01'], tz='Asia/Tokyo'), | ||
TimedeltaIndex(['1 days'])], | ||
['datetime64[ns, Asia/Tokyo]', 'timedelta'])]) | ||
@pytest.mark.parametrize('klass', [Index, Series]) | ||
def test_get_dtype_kinds(klass, to_concat, expected): | ||
to_concat_klass = [klass(c) for c in to_concat] | ||
result = _concat.get_dtype_kinds(to_concat_klass) | ||
assert result == set(expected) | ||
|
||
|
||
@pytest.mark.parametrize('to_concat, expected', [ | ||
# because we don't have Period dtype (yet), | ||
# Series results in object dtype | ||
([PeriodIndex(['2011-01'], freq='M'), | ||
PeriodIndex(['2011-01'], freq='M')], ['period[M]']), | ||
([Series([Period('2011-01', freq='M')]), | ||
Series([Period('2011-02', freq='M')])], ['object']), | ||
([PeriodIndex(['2011-01'], freq='M'), | ||
PeriodIndex(['2011-01'], freq='D')], ['period[M]', 'period[D]']), | ||
([Series([Period('2011-01', freq='M')]), | ||
Series([Period('2011-02', freq='D')])], ['object'])]) | ||
def test_get_dtype_kinds_period(to_concat, expected): | ||
result = _concat.get_dtype_kinds(to_concat) | ||
assert result == set(expected) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this test is actually necessary? Split this off from the
test_invalid_dtype_error
, as it appears to be testing valid instead of invalid dtypes. Previously this didn't have any type ofassert
statement; it just calledpandas_dtype
and the test passed if no error was raised.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is ok, this is just testing that pandas_dtype doesn't raise on numpy dtypes