-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST: Added fromisocalendar test cases #30395
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
Conversation
This is a good start. Next up you need to add tests for the new functionality. Those will go in |
if you look at the CI results you'll see some red checkmarks. you're going to need to click through to find out why this is failing so you can fix it (spoiler: test_missing_public_nat_methods) |
e1a6106
to
82065c5
Compare
pandas/_libs/tslibs/nattype.pyx
Outdated
Return a new Timestamp corresponding to the | ||
ISO calendar date specified by year, week and day. | ||
""" | ||
) |
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.
good, you figured out the test that was failiing before
Good going so far. You changed it to raise in older python versions and fixed the test that was broken before. But now if you look at the CI you'll see there is a different test that is broken. So the next step is to look at the CI log to tell what test(s) are failing (spoiler: the test you added is failing when run in older pythons) and figure out how to fix it. (Ideally also you'll run the tests locally to make sure they pass on your computer before pushing, let me know if you have trouble with that) This becomes more intuitive with experience. |
I did, the problem is I have python 3.8 Anyway, I'll fix it. Is there's more elegant way rather than making an |
Good progress |
d742180
to
280d04e
Compare
pandas/_libs/tslibs/timestamps.pyx
Outdated
def fromisocalendar(cls, year, week, day): | ||
""" | ||
Timestamp.fromisocalendar(year, week, day) | ||
|
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.
can you add a full doc-string here
pandas/_libs/tslibs/timestamps.pyx
Outdated
Return a new Timestamp corresponding to the | ||
ISO calendar date specified by year, week and day. | ||
""" | ||
import pandas.compat as compat |
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.
@jbrockmendel can we not import this at the top? (else we should have these constants in a .pyx somewhere
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.
importing this at the top is not an option, but we can either put it in e.g. tslibs.util or from cpython.version cimport PY_MINOR_VERSION
.
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.
right should prob make a standard way of doing this (though i don't think we need to have version checks too often in cython these days)
So I just tried pd.Timestamp.fromisocalendar on 0.25.3 and it works fine (i.e. correctly returns a Timestamp). I think we need a test for this, but the actual implementation in the cython file is unnecessary. |
280d04e
to
88468fa
Compare
So remove the code here? (Removed the new created method?) |
I think the test will still pass, so yes. |
88468fa
to
029954b
Compare
Since I really didn't add anything new to the code base (except test cases). Can #28115 be closed? |
01b9647
to
e7327e7
Compare
@MomIsBestFriend seems like there are some CI failures for py37 and earlier. |
e7327e7
to
de89a09
Compare
pandas/_libs/tslibs/nattype.pyx
Outdated
@@ -426,6 +426,7 @@ class NaTType(_NaT): | |||
toordinal = _make_error_func('toordinal', datetime) | |||
tzname = _make_error_func('tzname', datetime) | |||
utcoffset = _make_error_func('utcoffset', datetime) | |||
fromisocalendar = _make_error_func('fromisocalendar', datetime) |
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.
Does this need to be an in if PY38
block? In other words, will there be a Timestamp.fromisocalendar
for pandas 1.0 with python 3.7, or just py38 and above?
d6553e5
to
5315efc
Compare
d4956e1
to
e322603
Compare
pandas/tests/scalar/test_nat.py
Outdated
@@ -140,6 +141,10 @@ def test_round_nat(klass, method, freq): | |||
], | |||
) | |||
def test_nat_methods_raise(method): |
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.
can you put a skip on the argument instead, use pytest.param
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.
Didn't even knew that was an option. thank you for being specific!
code & tests lgtm. can you add a whatsnew node; other enhancements section is ok, just say added compatiblity with datetime.isocalender for PY >= 38 |
pandas/_libs/tslibs/nattype.pyx
Outdated
@@ -19,6 +19,8 @@ from pandas._libs.tslibs.util cimport ( | |||
get_nat, is_integer_object, is_float_object, is_datetime64_object, | |||
is_timedelta64_object) | |||
|
|||
import pandas.compat as compat |
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.
we really dont want this import here. how about from cpython.version cimport PY_MINOR_VERSION
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.
Fixed.
And just for I know for the next time, why we really don't want this import?
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.
we want to keep the dependency structure simple, and _libs, particularly tslibs is at the base of that structure, so avoids imports from elsewhere in pandas
thanks @MomIsBestFriend |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff