-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Closed
anirudnits
wants to merge
8
commits into
pandas-dev:master
from
anirudnits:add_test_in_test_frame.py_for_issue_#6942
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
187ad13
Added test test_datetimeField_after_setitem for issue #6942 in test_f…
anirudnits 80c52d6
Added sleep time of 1 second in between assignments
anirudnits 4e02832
Added test test_datetimeField_after_setitem_with_at in tests/generic/…
anirudnits 93f0385
Added test test_datetimeField_after_setitem_with_at in tests/generic/…
anirudnits 259013a
Made the required changes
anirudnits 768d553
Merge branch 'master' of https://github.com/pandas-dev/pandas into ad…
anirudnits a4db260
Merge branch 'master' of https://github.com/pandas-dev/pandas into ad…
anirudnits 9cbf34c
Fixed a typo which was causing a ValueError
anirudnits 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
Added sleep time of 1 second in between assignments
- Loading branch information
commit 80c52d60baf534a62de5cad659ee01921b2660e7
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import numpy as np | ||
import pytest | ||
from datetime import datetime | ||
import time | ||
|
||
import pandas.util._test_decorators as td | ||
|
||
|
@@ -302,13 +303,17 @@ def test_datetimeField_after_setitem(self): | |
df.at[start, "timenow"] = datetime.today() # initial time. | ||
time1 = df.at[start, "timenow"] | ||
|
||
time.sleep(1) # sleep time of 1 second in between assignments. | ||
|
||
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. | ||
|
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
2F00
.
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
sleep
calls are not needed.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.
Some tests were failing with AssertionError, so added those.
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.
Why were
AssertionError
s being 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.
I tried the same code on my computer and got the following results:
time1: 2019-10-04 23:23:31.911241
time2: 2019-10-04 23:23:31.911534
time3: 2019-10-04 23:23:31.912060
that is a time difference of 10^(-3) between the time1 and time2.Now if both the statements are executed within a time frame of <= 10^(-6) then the two will match. So that's why I thought of adding the sleep in between time1, time2 and time3 to ascertain this doesn't happen.
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.
The tests should generally be
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.
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".
So, what the test should check is that the dtype of timenow column remains unchanged after setting the Live column to True with at. For that I could use the assert_series_equal and check the dtype of timenow before and after.
Is that right?
Uh oh!
There was an error while loading. Please reload this page.
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 test should check that the
timenow
column changes oncedf.Live = True
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Some points:
For the general template of tests that is used in pandas/tests, most of them assert that either two DataFrames or Series are equal and call the predefined functions
tm.assert_something_equal
. However in this case we assert the column actually changes value and I couldn't find a function for such a case intm
and therefore wrote the individual assert statements for the different values in thetimenow
column(asserting that they are not equal).Without the sleep statements inserted, some checks were failing. When I viewed the log of the failed tests I observed that the error was because
assert not time1 == time2
was evaluating to
assert not datetime.datetime(2019, 10, 4, 16, 12, 38, 392372) == datetime.datetime(2019, 10, 4, 16, 12, 38, 392372)
So I realized that this could only occur if both the statements are run within a time-frame < 10^(-6). When I added the sleep statements the checks passed.
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.
You will still use
tm.assert_frame_equal
. You will have to construct the expected dataframe from scratchThere 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.
Thanks, couldn't come up with that! Will make the necessary changes and resubmit the PR.