Skip to content

Commit c6305b1

Browse files
committed
DOC: improve pd.Timestamp docs with more examples and clarify different forms of API usage
1 parent c28b624 commit c6305b1

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

pandas/_libs/tslibs/nattype.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ class NaTType(_NaT):
381381
382382
Parameters
383383
----------
384-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
384+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
385385
Time zone for time which Timestamp will be converted to.
386386
None will remove timezone holding UTC time.
387387
@@ -407,7 +407,7 @@ class NaTType(_NaT):
407407
date corresponding to a proleptic Gregorian ordinal
408408
freq : str, DateOffset
409409
Offset which Timestamp will have
410-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
410+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
411411
Time zone for time which Timestamp will have.
412412
offset : str, DateOffset
413413
Deprecated, use freq
@@ -430,7 +430,7 @@ class NaTType(_NaT):
430430
431431
Parameters
432432
----------
433-
tz : string / timezone object, default None
433+
tz : str or timezone object, default None
434434
Timezone to localize to
435435
""")
436436
today = _make_nat_func('today', # noqa:E128
@@ -443,7 +443,7 @@ class NaTType(_NaT):
443443
444444
Parameters
445445
----------
446-
tz : string / timezone object, default None
446+
tz : str or timezone object, default None
447447
Timezone to localize to
448448
""")
449449
round = _make_nat_func('round', # noqa:E128
@@ -485,7 +485,7 @@ class NaTType(_NaT):
485485
486486
Parameters
487487
----------
488-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
488+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
489489
Time zone for time which Timestamp will be converted to.
490490
None will remove timezone holding UTC time.
491491
@@ -505,7 +505,7 @@ class NaTType(_NaT):
505505
506506
Parameters
507507
----------
508-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
508+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
509509
Time zone for time which Timestamp will be converted to.
510510
None will remove timezone holding local time.
511511

pandas/_libs/tslibs/timestamps.pyx

+20-9
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ cdef class _Timestamp(datetime):
369369
class Timestamp(_Timestamp):
370370
"""Pandas replacement for datetime.datetime
371371
372-
TimeStamp is the pandas equivalent of python's Datetime
372+
Timestamp is the pandas equivalent of python's Datetime
373373
and is interchangable with it in most cases. It's the type used
374374
for the entries that make up a DatetimeIndex, and other timeseries
375375
oriented data structures in pandas.
@@ -380,10 +380,11 @@ class Timestamp(_Timestamp):
380380
Value to be converted to Timestamp
381381
freq : str, DateOffset
382382
Offset which Timestamp will have
383-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
383+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
384384
Time zone for time which Timestamp will have.
385-
unit : string
386-
numpy unit used for conversion, if ts_input is int or float
385+
unit : str
386+
Unit used for conversion if ts_input is of type int or float.
387+
For example, 's' means seconds and 'ms' means milliseconds.
387388
offset : str, DateOffset
388389
Deprecated, use freq
389390
@@ -405,9 +406,19 @@ class Timestamp(_Timestamp):
405406
406407
Examples
407408
--------
409+
Using the primary calling convention:
410+
408411
>>> pd.Timestamp('2017-01-01T12')
409412
Timestamp('2017-01-01 12:00:00')
410413
414+
>>> pd.Timestamp(1513393355.5, unit='s')
415+
Timestamp('2017-12-16 03:02:35.500000')
416+
417+
>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific')
418+
Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
419+
420+
Using the other two forms that minic the API for ``datetime.datetime``:
421+
411422
>>> pd.Timestamp(2017, 1, 1, 12)
412423
Timestamp('2017-01-01 12:00:00')
413424
@@ -429,7 +440,7 @@ class Timestamp(_Timestamp):
429440
date corresponding to a proleptic Gregorian ordinal
430441
freq : str, DateOffset
431442
Offset which Timestamp will have
432-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
443+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
433444
Time zone for time which Timestamp will have.
434445
offset : str, DateOffset
435446
Deprecated, use freq
@@ -447,7 +458,7 @@ class Timestamp(_Timestamp):
447458
448459
Parameters
449460
----------
450-
tz : string / timezone object, default None
461+
tz : str or timezone object, default None
451462
Timezone to localize to
452463
"""
453464
if is_string_object(tz):
@@ -465,7 +476,7 @@ class Timestamp(_Timestamp):
465476
466477
Parameters
467478
----------
468-
tz : string / timezone object, default None
479+
tz : str or timezone object, default None
469480
Timezone to localize to
470481
"""
471482
return cls.now(tz)
@@ -774,7 +785,7 @@ class Timestamp(_Timestamp):
774785
775786
Parameters
776787
----------
777-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
788+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
778789
Time zone for time which Timestamp will be converted to.
779790
None will remove timezone holding local time.
780791
@@ -828,7 +839,7 @@ class Timestamp(_Timestamp):
828839
829840
Parameters
830841
----------
831-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
842+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
832843
Time zone for time which Timestamp will be converted to.
833844
None will remove timezone holding UTC time.
834845

0 commit comments

Comments
 (0)