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 all 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Other enhancements
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
- :meth:`Series.map` now accepts ``collections.abc.Mapping`` subclasses as a mapper (:issue:`29733`)
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30296`)
- :meth:`Timestamp.fromisocalendar` is now compatible with python 3.8 and above (:issue:`28115`)



Expand Down
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ from cpython.object cimport (
from cpython.datetime cimport (datetime,
PyDateTime_Check, PyDelta_Check,
PyDateTime_IMPORT)

from cpython.version cimport PY_MINOR_VERSION

PyDateTime_IMPORT

import numpy as np
Expand All @@ -19,6 +22,7 @@ from pandas._libs.tslibs.util cimport (
get_nat, is_integer_object, is_float_object, is_datetime64_object,
is_timedelta64_object)


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

# "fromisocalendar" was introduced in 3.8
if PY_MINOR_VERSION >= 8:
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