@@ -30,6 +30,7 @@ from util cimport (is_integer_object, is_float_object, is_datetime64_object,
30
30
is_timedelta64_object, INT64_MAX)
31
31
cimport util
32
32
33
+ from cpython.datetime cimport PyTZInfo_Check
33
34
# this is our datetime.pxd
34
35
from datetime cimport (
35
36
pandas_datetimestruct,
@@ -68,7 +69,7 @@ from .tslibs.parsing import parse_datetime_string
68
69
69
70
cimport cython
70
71
71
- from pandas.compat import iteritems, callable
72
+ from pandas.compat import iteritems
72
73
73
74
import collections
74
75
import warnings
@@ -373,12 +374,23 @@ class Timestamp(_Timestamp):
373
374
FutureWarning )
374
375
freq = offset
375
376
377
+ if tzinfo is not None :
378
+ if not PyTZInfo_Check(tzinfo):
379
+ # tzinfo must be a datetime.tzinfo object, GH#17690
380
+ raise TypeError (' tzinfo must be a datetime.tzinfo object, '
381
+ ' not %s ' % type (tzinfo))
382
+ elif tz is not None :
383
+ raise ValueError (' Can provide at most one of tz, tzinfo' )
384
+
376
385
if ts_input is _no_input:
377
386
# User passed keyword arguments.
387
+ if tz is None :
388
+ # Handle the case where the user passes `tz` and not `tzinfo`
389
+ tz = tzinfo
378
390
return Timestamp(datetime(year, month, day, hour or 0 ,
379
391
minute or 0 , second or 0 ,
380
392
microsecond or 0 , tzinfo),
381
- tz = tzinfo )
393
+ tz = tz )
382
394
elif is_integer_object(freq):
383
395
# User passed positional arguments:
384
396
# Timestamp(year, month, day[, hour[, minute[, second[,
@@ -387,6 +399,10 @@ class Timestamp(_Timestamp):
387
399
year or 0 , month or 0 , day or 0 ,
388
400
hour), tz = hour)
389
401
402
+ if tzinfo is not None :
403
+ # User passed tzinfo instead of tz; avoid silently ignoring
404
+ tz, tzinfo = tzinfo, None
405
+
390
406
ts = convert_to_tsobject(ts_input, tz, unit, 0 , 0 )
391
407
392
408
if ts.value == NPY_NAT:
0 commit comments