@@ -216,7 +216,6 @@ cdef inline bint _is_fixed_offset(object tz):
216
216
217
217
218
218
_zero_time = datetime_time(0 , 0 )
219
- _no_unit = object ()
220
219
221
220
# Python front end to C extension type _Timestamp
222
221
# This serves as the box for datetime64
@@ -290,34 +289,41 @@ class Timestamp(_Timestamp):
290
289
return cls (datetime.combine(date, time))
291
290
292
291
def __new__ (cls ,
293
- object ts_input , object offset = None , tz = None , unit = _no_unit,
294
- minute = 0 , second = 0 , microsecond = 0 , tzinfo = None ):
292
+ object ts_input = None , object offset = None , tz = None , unit = None ,
293
+ year = None , month = None , day = None ,
294
+ hour = None , minute = None , second = None , microsecond = None ,
295
+ tzinfo = None ):
295
296
# The parameter list folds together legacy parameter names (the first
296
- # four) and positional parameter names from pydatetime (starting with
297
- # `minute`).
297
+ # four) and positional and keyword parameter names from pydatetime.
298
298
#
299
- # When using the pydatetime form, the first three parameters are
300
- # required, but the fourth (called `unit` but standing in for `hour`)
301
- # is optional. However, when using the legacy form, only the first
302
- # parameter is required and the fourth parameter defaults to `None`.
303
- # We use a special non-`None` constant to distinguish when callers
304
- # pass `None` as the fourth pydatetime parameter.
299
+ # There are three calling forms:
300
+ # - In the legacy form, the first parameter, ts_input, is required
301
+ # and may be datetime-like, str, int, or float. The second parameter,
302
+ # offset, is optional and may be str or DateOffset.
303
+ # - ints in the first, second, and third arguments indicate
304
+ # pydatetime positional arguments. Only the first 8 arguments
305
+ # (standing in for year, month, day, hour, minute, second,
306
+ # microsecond, tzinfo) may be non-None. As a shortcut, we just check
307
+ # that the second argument is an int.
308
+ # - Nones for the first four (legacy) arguments indicate pydatetime
309
+ # keyword arguments. year, month, and day are required. As a
310
+ # shortcut, we just check that the first argument is None.
311
+ #
312
+ # Mixing pydatetime positional and keyword arguments is forbidden!
305
313
306
314
cdef _TSObject ts
307
315
cdef _Timestamp ts_base
308
316
309
- if offset is not None and is_integer_object(offset):
317
+ if ts_input is None :
318
+ # User passed keyword arguments.
319
+ return Timestamp(datetime(year, month, day, hour or 0 ,
320
+ minute or 0 , second or 0 , microsecond or 0 , tzinfo),
321
+ tz = tzinfo)
322
+ if is_integer_object(offset):
310
323
# User passed positional arguments:
311
324
# Timestamp(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
312
- # When using the positional form, the first three parameters are
313
- # required. Assign defaults to the rest.
314
- if unit is _no_unit:
315
- unit = 0
316
- # Forward positional arguments to datetime constructor.
317
- return Timestamp(datetime(ts_input, offset, tz, unit, minute, second, microsecond, tzinfo),
318
- tz = tzinfo)
319
- elif unit is _no_unit:
320
- unit = None
325
+ return Timestamp(datetime(ts_input, offset, tz, unit or 0 ,
326
+ year or 0 , month or 0 , day or 0 , hour), tz = hour)
321
327
322
328
ts = convert_to_tsobject(ts_input, tz, unit, 0 , 0 )
323
329
0 commit comments