Skip to content

Commit 0bbfa0a

Browse files
ShaharNavehjreback
authored andcommitted
TST: Added fromisocalendar test cases (#30395)
1 parent f12567f commit 0bbfa0a

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Other enhancements
227227
- Added new writer for exporting Stata dta files in version 118, ``StataWriter118``. This format supports exporting strings containing Unicode characters (:issue:`23573`)
228228
- :meth:`Series.map` now accepts ``collections.abc.Mapping`` subclasses as a mapper (:issue:`29733`)
229229
- The ``pandas.datetime`` class is now deprecated. Import from ``datetime`` instead (:issue:`30296`)
230+
- :meth:`Timestamp.fromisocalendar` is now compatible with python 3.8 and above (:issue:`28115`)
230231

231232

232233

pandas/_libs/tslibs/nattype.pyx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ from cpython.object cimport (
55
from cpython.datetime cimport (datetime,
66
PyDateTime_Check, PyDelta_Check,
77
PyDateTime_IMPORT)
8+
9+
from cpython.version cimport PY_MINOR_VERSION
10+
811
PyDateTime_IMPORT
912

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

25+
2226
# ----------------------------------------------------------------------
2327
# Constants
2428
nat_strings = {'NaT', 'nat', 'NAT', 'nan', 'NaN', 'NAN'}
@@ -427,6 +431,10 @@ class NaTType(_NaT):
427431
tzname = _make_error_func('tzname', datetime)
428432
utcoffset = _make_error_func('utcoffset', datetime)
429433

434+
# "fromisocalendar" was introduced in 3.8
435+
if PY_MINOR_VERSION >= 8:
436+
fromisocalendar = _make_error_func('fromisocalendar', datetime)
437+
430438
# ----------------------------------------------------------------------
431439
# The remaining methods have docstrings copy/pasted from the analogous
432440
# Timestamp methods.

pandas/tests/scalar/test_nat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ def test_round_nat(klass, method, freq):
123123
"dst",
124124
"fromordinal",
125125
"fromtimestamp",
126+
pytest.param(
127+
"fromisocalendar",
128+
marks=pytest.mark.skipif(
129+
not compat.PY38,
130+
reason="'fromisocalendar' was added in stdlib datetime in python 3.8",
131+
),
132+
),
126133
"isocalendar",
127134
"strftime",
128135
"strptime",
@@ -297,6 +304,8 @@ def test_overlap_public_nat_methods(klass, expected):
297304
# "fromisoformat" was introduced in 3.7
298305
if klass is Timestamp and not compat.PY37:
299306
expected.remove("fromisoformat")
307+
308+
# "fromisocalendar" was introduced in 3.8
300309
if klass is Timestamp and not compat.PY38:
301310
expected.remove("fromisocalendar")
302311

pandas/tests/scalar/timestamp/test_timestamp.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from pandas._libs.tslibs import conversion
1616
from pandas._libs.tslibs.timezones import dateutil_gettz as gettz, get_timezone
17+
import pandas.compat as compat
1718
from pandas.compat.numpy import np_datetime64_compat
1819
from pandas.errors import OutOfBoundsDatetime
1920
import pandas.util._test_decorators as td
@@ -700,6 +701,19 @@ class SubDatetime(datetime):
700701
expected = Timestamp(2000, 1, 1)
701702
assert result == expected
702703

704+
@pytest.mark.skipif(
705+
not compat.PY38,
706+
reason="datetime.fromisocalendar was added in Python version 3.8",
707+
)
708+
def test_constructor_fromisocalendar(self):
709+
# GH 30395
710+
expected_timestamp = Timestamp("2000-01-03 00:00:00")
711+
expected_stdlib = datetime.fromisocalendar(2000, 1, 1)
712+
result = Timestamp.fromisocalendar(2000, 1, 1)
713+
assert result == expected_timestamp
714+
assert result == expected_stdlib
715+
assert isinstance(result, Timestamp)
716+
703717

704718
class TestTimestamp:
705719
def test_tz(self):

0 commit comments

Comments
 (0)