@@ -30,6 +30,7 @@ from util cimport (is_integer_object, is_float_object, is_datetime64_object,
3030 is_timedelta64_object, INT64_MAX)
3131cimport util
3232
33+ from cpython.datetime cimport PyTZInfo_Check
3334# this is our datetime.pxd
3435from datetime cimport (
3536 pandas_datetimestruct,
@@ -68,7 +69,7 @@ from .tslibs.parsing import parse_datetime_string
6869
6970cimport cython
7071
71- from pandas.compat import iteritems, callable
72+ from pandas.compat import iteritems
7273
7374import collections
7475import warnings
@@ -373,12 +374,23 @@ class Timestamp(_Timestamp):
373374 FutureWarning )
374375 freq = offset
375376
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+
376385 if ts_input is _no_input:
377386 # User passed keyword arguments.
387+ if tz is None :
388+ # Handle the case where the user passes `tz` and not `tzinfo`
389+ tz = tzinfo
378390 return Timestamp(datetime(year, month, day, hour or 0 ,
379391 minute or 0 , second or 0 ,
380392 microsecond or 0 , tzinfo),
381- tz = tzinfo )
393+ tz = tz )
382394 elif is_integer_object(freq):
383395 # User passed positional arguments:
384396 # Timestamp(year, month, day[, hour[, minute[, second[,
@@ -387,6 +399,10 @@ class Timestamp(_Timestamp):
387399 year or 0 , month or 0 , day or 0 ,
388400 hour), tz = hour)
389401
402+ if tzinfo is not None :
403+ # User passed tzinfo instead of tz; avoid silently ignoring
404+ tz, tzinfo = tzinfo, None
405+
390406 ts = convert_to_tsobject(ts_input, tz, unit, 0 , 0 )
391407
392408 if ts.value == NPY_NAT:
0 commit comments