Skip to content

Commit 8e33a71

Browse files
mortadajreback
authored andcommitted
DOC: improve pd.Timestamp docs with more examples and clarify different forms of API usage (#18811)
1 parent 15f6cdb commit 8e33a71

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-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

+25-9
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ cdef class _Timestamp(datetime):
372372
class Timestamp(_Timestamp):
373373
"""Pandas replacement for datetime.datetime
374374
375-
TimeStamp is the pandas equivalent of python's Datetime
375+
Timestamp is the pandas equivalent of python's Datetime
376376
and is interchangable with it in most cases. It's the type used
377377
for the entries that make up a DatetimeIndex, and other timeseries
378378
oriented data structures in pandas.
@@ -383,10 +383,12 @@ class Timestamp(_Timestamp):
383383
Value to be converted to Timestamp
384384
freq : str, DateOffset
385385
Offset which Timestamp will have
386-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
386+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
387387
Time zone for time which Timestamp will have.
388-
unit : string
389-
numpy unit used for conversion, if ts_input is int or float
388+
unit : str
389+
Unit used for conversion if ts_input is of type int or float. The
390+
valid values are 'D', 'h', 'm', 's', 'ms', 'us', and 'ns'. For
391+
example, 's' means seconds and 'ms' means milliseconds.
390392
offset : str, DateOffset
391393
Deprecated, use freq
392394
@@ -408,9 +410,23 @@ class Timestamp(_Timestamp):
408410
409411
Examples
410412
--------
413+
Using the primary calling convention:
414+
415+
This converts a datetime-like string
411416
>>> pd.Timestamp('2017-01-01T12')
412417
Timestamp('2017-01-01 12:00:00')
413418
419+
This converts a float representing a Unix epoch in units of seconds
420+
>>> pd.Timestamp(1513393355.5, unit='s')
421+
Timestamp('2017-12-16 03:02:35.500000')
422+
423+
This converts an int representing a Unix-epoch in units of seconds
424+
and for a particular timezone
425+
>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific')
426+
Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')
427+
428+
Using the other two forms that mimic the API for ``datetime.datetime``:
429+
414430
>>> pd.Timestamp(2017, 1, 1, 12)
415431
Timestamp('2017-01-01 12:00:00')
416432
@@ -432,7 +448,7 @@ class Timestamp(_Timestamp):
432448
date corresponding to a proleptic Gregorian ordinal
433449
freq : str, DateOffset
434450
Offset which Timestamp will have
435-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
451+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
436452
Time zone for time which Timestamp will have.
437453
offset : str, DateOffset
438454
Deprecated, use freq
@@ -450,7 +466,7 @@ class Timestamp(_Timestamp):
450466
451467
Parameters
452468
----------
453-
tz : string / timezone object, default None
469+
tz : str or timezone object, default None
454470
Timezone to localize to
455471
"""
456472
if is_string_object(tz):
@@ -468,7 +484,7 @@ class Timestamp(_Timestamp):
468484
469485
Parameters
470486
----------
471-
tz : string / timezone object, default None
487+
tz : str or timezone object, default None
472488
Timezone to localize to
473489
"""
474490
return cls.now(tz)
@@ -777,7 +793,7 @@ class Timestamp(_Timestamp):
777793
778794
Parameters
779795
----------
780-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
796+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
781797
Time zone for time which Timestamp will be converted to.
782798
None will remove timezone holding local time.
783799
@@ -831,7 +847,7 @@ class Timestamp(_Timestamp):
831847
832848
Parameters
833849
----------
834-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
850+
tz : str, pytz.timezone, dateutil.tz.tzfile or None
835851
Time zone for time which Timestamp will be converted to.
836852
None will remove timezone holding UTC time.
837853

0 commit comments

Comments
 (0)