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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ----------------------------------------------------------------------
# Constants
nat_strings = {'NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'}
Expand Down Expand Up @@ -427,6 +429,10 @@ class NaTType(_NaT):
tzname = _make_error_func('tzname', datetime)
utcoffset = _make_error_func('utcoffset', datetime)

# "fromisocalendar" was introduced in 3.8
if compat.PY38:
fromisocalendar = _make_error_func('fromisocalendar', datetime)

# ----------------------------------------------------------------------
# The remaining methods have docstrings copy/pasted from the analogous
# Timestamp methods.
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/scalar/test_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ def test_round_nat(klass, method, freq):
"dst",
"fromordinal",
"fromtimestamp",
pytest.param(
"fromisocalendar",
marks=pytest.mark.skipif(
not compat.PY38,
reason="'fromisocalendar' was added in stdlib datetime in python 3.8",
),
),
"isocalendar",
"strftime",
"strptime",
Expand Down Expand Up @@ -297,6 +304,8 @@ def test_overlap_public_nat_methods(klass, expected):
# "fromisoformat" was introduced in 3.7
if klass is Timestamp and not compat.PY37:
expected.remove("fromisoformat")

# "fromisocalendar" was introduced in 3.8
if klass is Timestamp and not compat.PY38:
expected.remove("fromisocalendar")

Expand Down
14 changes: 14 additions & 0 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from pandas._libs.tslibs import conversion
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz, get_timezone
import pandas.compat as compat
from pandas.compat.numpy import np_datetime64_compat
from pandas.errors import OutOfBoundsDatetime
import pandas.util._test_decorators as td
Expand Down Expand Up @@ -700,6 +701,19 @@ class SubDatetime(datetime):
expected = Timestamp(2000, 1, 1)
assert result == expected

@pytest.mark.skipif(
not compat.PY38,
reason="datetime.fromisocalendar was added in Python version 3.8",
)
def test_constructor_fromisocalendar(self):
# GH 30395
expected_timestamp = Timestamp("2000-01-03 00:00:00")
expected_stdlib = datetime.fromisocalendar(2000, 1, 1)
result = Timestamp.fromisocalendar(2000, 1, 1)
assert result == expected_timestamp
assert result == expected_stdlib
assert isinstance(result, Timestamp)


class TestTimestamp:
def test_tz(self):
Expand Down