-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Added test test_datetimeField_after_setitem for issue #6942 #28790
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
Changes from 2 commits
187ad13
80c52d6
4e02832
93f0385
259013a
768d553
a4db260
9cbf34c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
import numpy as np | ||
import pytest | ||
from datetime import datetime | ||
import time | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
|
@@ -287,3 +289,36 @@ def test_deepcopy_empty(self): | |
empty_frame_copy = deepcopy(empty_frame) | ||
|
||
self._compare(empty_frame_copy, empty_frame) | ||
|
||
def test_datetimeField_after_setitem(self): | ||
# This test covers the unexpected behaviour of datetimeField when using | ||
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. datetimeField -> datetime64 column ? |
||
# setitem on another column as reported in issue #6942 | ||
|
||
start = pd.to_datetime("20140401") | ||
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 use pd.Timestamp here |
||
|
||
df = pd.DataFrame( | ||
index=pd.date_range(start, periods=1), columns=["timenow", "Live"] | ||
) | ||
|
||
df.at[start, "timenow"] = datetime.today() # initial time. | ||
time1 = df.at[start, "timenow"] | ||
|
||
time.sleep(1) # sleep time of 1 second in between assignments. | ||
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. These 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. Some tests were failing with AssertionError, so added those. 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 were 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. I tried the same code on my computer and got the following results: 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. The tests should generally be
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. Sorry I misread the problem and was writing the test to check if the timenow column changes value after setting the Live column with "at". 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 test should check that the i.e. the example in #6942 (comment) is the fixed behavior that we want to test for. 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. Some points:
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. You will still use
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. Thanks, couldn't come up with that! Will make the necessary changes and resubmit the PR. |
||
|
||
df.at[ | ||
start, "timenow" | ||
] = datetime.today() # modified time before 'Live' column is set. | ||
time2 = df.at[start, "timenow"] | ||
|
||
df.Live = True # setting the 'Live' column to True. | ||
|
||
time.sleep(1) # sleep time of 1 second in between assignments. | ||
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. These 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. Some checks were failing with AssertionError, so I added those |
||
|
||
df.at[ | ||
start, "timenow" | ||
] = datetime.today() # modified time after 'Live' column is set. | ||
time3 = df.at[start, "timenow"] | ||
|
||
assert not time1 == time2 | ||
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. We would like to construct 2 dataframes here and use
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. I thought of the same but the whole point of the test is to make sure that the datetimeField changes with each assignment and as such would require to assert that frames are not equal, that's went with this. Couldn't find a more elegant way round this. |
||
assert not time2 == time3 | ||
assert not time3 == time1 |
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.
Mention the use of
at
in the title:test_datetime_setitem_with_at
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.
Sure