Skip to content

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

Merged
merged 9 commits into from
Jan 6, 2020
Merged

Conversation

ShaharNaveh
Copy link
Member

@ShaharNaveh ShaharNaveh commented Dec 21, 2019

@ShaharNaveh
Copy link
Member Author

cc @jbrockmendel

@ShaharNaveh ShaharNaveh changed the title Added class method COMPACT: fromisocalendar method to Timestamp Dec 21, 2019
@jbrockmendel
Copy link
Member

This is a good start. Next up you need to add tests for the new functionality. Those will go in pandas.tests.scalar.timestamp.test_timestamp.TestTimestampConstructors. Look at the tests we have there for the other similar Timestamp classmethods to get an idea of what the tests should look like

@jbrockmendel
Copy link
Member

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)

@ShaharNaveh ShaharNaveh force-pushed the Fix-28115 branch 2 times, most recently from e1a6106 to 82065c5 Compare December 22, 2019 01:22
@ShaharNaveh ShaharNaveh changed the title COMPACT: fromisocalendar method to Timestamp COMPAT: fromisocalendar method to Timestamp Dec 22, 2019
Return a new Timestamp corresponding to the
ISO calendar date specified by year, week and day.
"""
)
Copy link
Member

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

@jbrockmendel
Copy link
Member

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.

@ShaharNaveh
Copy link
Member Author

ShaharNaveh commented Dec 22, 2019

Ideally also you'll run the tests locally to make sure they pass on your computer before pushing

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 if statement checking the python version?

@ShaharNaveh ShaharNaveh marked this pull request as ready for review December 22, 2019 05:16
@jbrockmendel
Copy link
Member

Good progress

@ShaharNaveh ShaharNaveh force-pushed the Fix-28115 branch 2 times, most recently from d742180 to 280d04e Compare December 22, 2019 20:35
@gfyoung gfyoung added Compat pandas objects compatability with Numpy or Python functions Datetime Datetime data dtype labels Dec 22, 2019
def fromisocalendar(cls, year, week, day):
"""
Timestamp.fromisocalendar(year, week, day)

Copy link
Contributor

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

Return a new Timestamp corresponding to the
ISO calendar date specified by year, week and day.
"""
import pandas.compat as compat
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

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)

@jbrockmendel
Copy link
Member

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.

@ShaharNaveh
Copy link
Member Author

ShaharNaveh commented Dec 24, 2019

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.

So remove the code here?

https://github.com/MomIsBestFriend/pandas/blob/88468fa3604457319401b126764ed49be3e6d15f/pandas/_libs/tslibs/timestamps.pyx#L340

(Removed the new created method?)

@jbrockmendel
Copy link
Member

(Removed the new created method?)

I think the test will still pass, so yes.

@ShaharNaveh ShaharNaveh changed the title COMPAT: fromisocalendar method to Timestamp TST: Added fromisocalendar test cases Dec 25, 2019
@ShaharNaveh
Copy link
Member Author

Since I really didn't add anything new to the code base (except test cases).

Can #28115 be closed?

@ShaharNaveh ShaharNaveh force-pushed the Fix-28115 branch 2 times, most recently from 01b9647 to e7327e7 Compare December 29, 2019 11:36
@TomAugspurger
Copy link
Contributor

@MomIsBestFriend seems like there are some CI failures for py37 and earlier.

@@ -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)
Copy link
Contributor

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?

@ShaharNaveh ShaharNaveh force-pushed the Fix-28115 branch 2 times, most recently from d6553e5 to 5315efc Compare December 31, 2019 13:14
@ShaharNaveh ShaharNaveh force-pushed the Fix-28115 branch 2 times, most recently from d4956e1 to e322603 Compare January 1, 2020 13:55
@jreback jreback removed this from the 1.0 milestone Jan 1, 2020
@@ -140,6 +141,10 @@ def test_round_nat(klass, method, freq):
],
)
def test_nat_methods_raise(method):
Copy link
Contributor

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

Copy link
Member Author

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!

@ShaharNaveh ShaharNaveh requested a review from jreback January 1, 2020 19:44
@TomAugspurger TomAugspurger added this to the 1.0 milestone Jan 2, 2020
@jreback
Copy link
Contributor

jreback commented Jan 3, 2020

code & tests lgtm. can you add a whatsnew node; other enhancements section is ok, just say added compatiblity with datetime.isocalender for PY >= 38

@@ -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
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

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

@jreback jreback merged commit 0bbfa0a into pandas-dev:master Jan 6, 2020
@jreback
Copy link
Contributor

jreback commented Jan 6, 2020

thanks @MomIsBestFriend

@ShaharNaveh ShaharNaveh deleted the Fix-28115 branch January 6, 2020 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

COMPAT: Implement Timestamp.fromisocalendar
6 participants