Skip to content

Commit 48b3438

Browse files
authored
BUG: Follow-up with Timestamp(nanoseconds) keyword only (#50545)
* BUG: Follow-up with Timestamp(nanoseconds) keyword only * Add test * Fix typing
1 parent c6d2f92 commit 48b3438

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ to each element individually, e.g. ::
462462

463463
Other API changes
464464
^^^^^^^^^^^^^^^^^
465-
- The ``freq``, ``tz``, ``nanosecond``, and ``unit`` keywords in the :class:`Timestamp` constructor are now keyword-only (:issue:`45307`)
465+
- The ``freq``, ``tz``, ``nanosecond``, and ``unit`` keywords in the :class:`Timestamp` constructor are now keyword-only (:issue:`45307`, :issue:`32526`)
466466
- Passing ``nanoseconds`` greater than 999 or less than 0 in :class:`Timestamp` now raises a ``ValueError`` (:issue:`48538`, :issue:`48255`)
467467
- :func:`read_csv`: specifying an incorrect number of columns with ``index_col`` of now raises ``ParserError`` instead of ``IndexError`` when using the c parser.
468468
- Default value of ``dtype`` in :func:`get_dummies` is changed to ``bool`` from ``uint8`` (:issue:`45848`)
@@ -821,7 +821,7 @@ Datetimelike
821821
- Bug in :func:`to_datetime` was throwing ``ValueError`` when parsing dates with ISO8601 format where some values were not zero-padded (:issue:`21422`)
822822
- Bug in :func:`to_datetime` was giving incorrect results when using ``format='%Y%m%d'`` and ``errors='ignore'`` (:issue:`26493`)
823823
- Bug in :func:`to_datetime` was failing to parse date strings ``'today'`` and ``'now'`` if ``format`` was not ISO8601 (:issue:`50359`)
824-
-
824+
- Bug in :func:`Timestamp.utctimetuple` raising a ``TypeError`` (:issue:`32174`)
825825

826826
Timedelta
827827
^^^^^^^^^

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,16 +1525,11 @@ class Timestamp(_Timestamp):
15251525
elif is_integer_object(year):
15261526
# User passed positional arguments:
15271527
# Timestamp(year, month, day[, hour[, minute[, second[,
1528-
# microsecond[, nanosecond[, tzinfo]]]]]])
1528+
# microsecond[, tzinfo]]]]])
15291529
ts_input = datetime(ts_input, year, month, day or 0,
15301530
hour or 0, minute or 0, second or 0, fold=fold or 0)
15311531
unit = None
15321532

1533-
if nanosecond is None:
1534-
# nanosecond was not passed as a keyword, but may have been
1535-
# passed positionally see test_constructor_nanosecond
1536-
nanosecond = microsecond
1537-
15381533
if getattr(ts_input, "tzinfo", None) is not None and tz is not None:
15391534
raise ValueError("Cannot pass a datetime or Timestamp with tzinfo with "
15401535
"the tz parameter. Use tz_convert instead.")

pandas/tests/scalar/timestamp/test_constructors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,13 @@ def test_constructor_fromordinal(self):
415415
nanosecond=1,
416416
tz="UTC",
417417
),
418-
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, None),
419-
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC),
418+
Timestamp(2000, 1, 2, 3, 4, 5, 6, None, nanosecond=1),
419+
Timestamp(2000, 1, 2, 3, 4, 5, 6, tz=pytz.UTC, nanosecond=1),
420420
],
421421
)
422422
def test_constructor_nanosecond(self, result):
423423
# GH 18898
424+
# As of 2.0 (GH 49416), nanosecond should not be accepted positionally
424425
expected = Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6), tz=result.tz)
425426
expected = expected + Timedelta(nanoseconds=1)
426427
assert result == expected

pandas/tests/scalar/timestamp/test_timestamp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
timezone,
88
)
99
import locale
10+
import time
1011
import unicodedata
1112

1213
from dateutil.tz import tzutc
@@ -1095,3 +1096,11 @@ def test_delimited_date():
10951096
result = Timestamp("13-01-2000")
10961097
expected = Timestamp(2000, 1, 13)
10971098
assert result == expected
1099+
1100+
1101+
def test_utctimetuple():
1102+
# GH 32174
1103+
ts = Timestamp("2000-01-01", tz="UTC")
1104+
result = ts.utctimetuple()
1105+
expected = time.struct_time((2000, 1, 1, 0, 0, 0, 5, 1, 0))
1106+
assert result == expected

0 commit comments

Comments
 (0)