-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Handle iterable of arrays in convert #16026
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 2 commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from datetime import datetime, date, timedelta, time | ||
import numpy as np | ||
import pytz | ||
import pytest | ||
|
||
import pandas as pd | ||
from pandas._libs import tslib, lib | ||
|
@@ -66,6 +67,27 @@ def test_is_list_like(): | |
assert not inference.is_list_like(f) | ||
|
||
|
||
@pytest.mark.parametrize('inner', [ | ||
[], [1], (1, ), (1, 2), {'a': 1}, set([1, 'a']), Series([1]), | ||
Series([]), Series(['a']).str, (x for x in range(5)) | ||
]) | ||
@pytest.mark.parametrize('outer', [ | ||
list, Series, np.array, tuple | ||
]) | ||
def test_is_nested_list_like_passes(inner, outer): | ||
result = outer([inner for _ in range(5)]) | ||
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. nice! |
||
assert inference.is_list_like(result) | ||
|
||
|
||
@pytest.mark.parametrize('obj', [ | ||
'abc', [], [1], (1,), ['a'], 'a', {'a'}, | ||
[1, 2, 3], Series([1]), DataFrame({"A": [1]}), | ||
([1, 2] for _ in range(5)), | ||
]) | ||
def test_is_nested_list_like_fails(obj): | ||
assert not inference.is_nested_list_like(obj) | ||
|
||
|
||
def test_is_dict_like(): | ||
passes = [{}, {'A': 1}, Series([1])] | ||
fails = ['1', 1, [1, 2], (1, 2), range(2), Index([1])] | ||
|
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 |
---|---|---|
|
@@ -138,6 +138,13 @@ def _assert_less(ts1, ts2): | |
_assert_less(ts, ts + Milli()) | ||
_assert_less(ts, ts + Micro(50)) | ||
|
||
def test_convert_nested(self): | ||
inner = [Timestamp('2017-01-01', Timestamp('2017-01-02'))] | ||
data = [inner, inner] | ||
result = self.dtc.convert(data, None, None) | ||
expected = [self.dtc.convert(x, None, None) for x in data] | ||
assert result == expected | ||
|
||
|
||
class TestPeriodConverter(tm.TestCase): | ||
|
||
|
@@ -196,3 +203,9 @@ def test_integer_passthrough(self): | |
rs = self.pc.convert([0, 1], None, self.axis) | ||
xp = [0, 1] | ||
self.assertEqual(rs, xp) | ||
|
||
def test_convert_nested(self): | ||
data = ['2012-1-1', '2012-1-2'] | ||
r1 = self.pc.convert(data, None, self.axis) | ||
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. this one is not nested (needs a |
||
r2 = [self.pc.convert(x, None, self.axis) for x in data] | ||
assert r1 == r2 |
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
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.
These examples are still copied from the
is_list_like
docstring I think