Skip to content

Commit b8f836c

Browse files
committed
Reorg params, change test, add attribute
1 parent 98e0b0c commit b8f836c

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

Diff for: pandas/_libs/tslibs/timestamps.pyx

+12-8
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ cdef class _Timestamp(datetime):
107107
cdef readonly:
108108
int64_t value, nanosecond
109109
object freq # frequency reference
110+
list _date_attributes
110111

111112
def __hash__(_Timestamp self):
112113
if self.nanosecond:
@@ -425,10 +426,10 @@ class Timestamp(_Timestamp):
425426
.. versionadded:: 0.19.0
426427
hour, minute, second, microsecond : int, optional, default 0
427428
.. versionadded:: 0.19.0
428-
tzinfo : datetime.tzinfo, optional, default None
429-
.. versionadded:: 0.19.0
430429
nanosecond : int, optional, default 0
431430
.. versionadded:: 0.23.0
431+
tzinfo : datetime.tzinfo, optional, default None
432+
.. versionadded:: 0.19.0
432433
433434
Notes
434435
-----
@@ -558,7 +559,7 @@ class Timestamp(_Timestamp):
558559
object freq=None, tz=None, unit=None,
559560
year=None, month=None, day=None,
560561
hour=None, minute=None, second=None, microsecond=None,
561-
tzinfo=None, nanosecond=None):
562+
nanosecond=None, tzinfo=None):
562563
# The parameter list folds together legacy parameter names (the first
563564
# four) and positional and keyword parameter names from pydatetime.
564565
#
@@ -582,6 +583,9 @@ class Timestamp(_Timestamp):
582583

583584
cdef _TSObject ts
584585

586+
_date_attributes = [year, month, day, hour, minute, second,
587+
microsecond, nanosecond]
588+
585589
if tzinfo is not None:
586590
if not PyTZInfo_Check(tzinfo):
587591
# tzinfo must be a datetime.tzinfo object, GH#17690
@@ -593,9 +597,9 @@ class Timestamp(_Timestamp):
593597
if is_string_object(ts_input):
594598
# User passed a date string to parse.
595599
# Check that the user didn't also pass a date attribute kwarg.
596-
date_attrs = [year, month, day, hour, minute, second, microsecond,
597-
nanosecond]
598-
if any(arg is not None for arg in date_attrs):
600+
#date_attrs = [year, month, day, hour, minute, second, microsecond,
601+
# nanosecond]
602+
if any(arg is not None for arg in _date_attributes):
599603
raise ValueError('Cannot pass a date attribute keyword '
600604
'argument when passing a date string')
601605

@@ -611,10 +615,10 @@ class Timestamp(_Timestamp):
611615
elif is_integer_object(freq):
612616
# User passed positional arguments:
613617
# Timestamp(year, month, day[, hour[, minute[, second[,
614-
# microsecond[, tzinfo]]]]])
618+
# microsecond[, nanosecond[, tzinfo]]]]]])
615619
return Timestamp(datetime(ts_input, freq, tz, unit or 0,
616620
year or 0, month or 0, day or 0,
617-
hour), nanosecond=minute, tz=hour)
621+
minute), nanosecond=hour, tz=minute)
618622

619623
if tzinfo is not None:
620624
# User passed tzinfo instead of tz; avoid silently ignoring

Diff for: pandas/tests/scalar/timestamp/test_timestamp.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,16 @@ def test_constructor_fromordinal(self):
386386
assert ts.to_pydatetime() == dt_tz
387387

388388
@pytest.mark.parametrize('result', [
389-
Timestamp(datetime(2000, 1, 1), nanosecond=1),
390-
Timestamp(year=2000, month=1, day=1, nanosecond=1),
391-
Timestamp(year=2000, month=1, day=1, tz='UTC', nanosecond=1),
392-
Timestamp(2000, 1, 1, 0, 0, 0, 0, None, 1),
393-
Timestamp(2000, 1, 1, 0, 0, 0, 0, pytz.UTC, 1)])
389+
Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6), nanosecond=1),
390+
Timestamp(year=2000, month=1, day=2, hour=3, minute=4, second=5,
391+
microsecond=6, nanosecond=1),
392+
Timestamp(year=2000, month=1, day=2, hour=3, minute=4, second=5,
393+
microsecond=6, nanosecond=1, tz='UTC'),
394+
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, None),
395+
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC)])
394396
def test_constructor_nanosecond(self, result):
395397
# GH 18898
396-
expected = Timestamp(datetime(2000, 1, 1), tz=result.tz)
398+
expected = Timestamp(datetime(2000, 1, 2, 3, 4, 5, 6), tz=result.tz)
397399
expected = expected + Timedelta(nanoseconds=1)
398400
assert result == expected
399401

0 commit comments

Comments
 (0)