-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: tests for inconsistent indexing with datetimes #20550
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
36528d5
TST: test added to GH9336
jcontesti c28394a
TST: code moved to test_indexing
jcontesti c1dfe56
TST: rest of the examples in #9336 added to new testing method
jcontesti 63350d3
TST: df declaration improved, numpy array assignation is now done wit…
jcontesti f7fb642
TST: datetime objects in numpy array are now directly numpy datetime …
jcontesti 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1548,6 +1548,25 @@ def test_setitem_single_column_mixed_datetime(self): | |
# pytest.raises( | ||
# Exception, df.loc.__setitem__, ('d', 'timestamp'), [nan]) | ||
|
||
def test_setitem_mixed_datetime(self): | ||
# GH 9336 | ||
expected = DataFrame({'a': [0, 0, 0, 0, 13, 14], | ||
'b': [pd.datetime(2012, 1, 1), | ||
1, | ||
'x', | ||
'y', | ||
pd.datetime(2013, 1, 1), | ||
pd.datetime(2014, 1, 1)]}) | ||
df = pd.DataFrame(np.zeros((6, 2), dtype=int), columns=['a', 'b']) | ||
df['b'] = pd.NaT | ||
df.loc[0, 'b'] = pd.datetime(2012, 1, 1) | ||
df.loc[1, 'b'] = 1 | ||
df.loc[[2, 3], 'b'] = 'x', 'y' | ||
A = pd.DataFrame([[13, pd.datetime(2013, 1, 1)], | ||
[14, pd.datetime(2014, 1, 1)]]) | ||
df.loc[[4, 5], ['a', 'b']] = A.values | ||
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. can you assign with a numpy array that you construct directly |
||
assert_frame_equal(df, expected) | ||
|
||
def test_setitem_frame(self): | ||
piece = self.frame.loc[self.frame.index[:2], ['A', 'B']] | ||
self.frame.loc[self.frame.index[-2]:, ['A', 'B']] = piece.values | ||
|
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.
this is failing because you are specify the dtype directly I think, just use
pd.DataFrame(0, columns = list('ab'), index=range(6))