From f1cc4bb7923d5719324c97f518c4c1248083ea93 Mon Sep 17 00:00:00 2001 From: MichaelMoyles Date: Sun, 11 Aug 2024 21:54:07 +0100 Subject: [PATCH 1/4] updated docstring for pandas.Timestamp.tz_localize, pandas.Timestamp.tzname and pandas.Timestamp.utcfromtimestamp --- ci/code_checks.sh | 3 --- pandas/_libs/tslibs/timestamps.pyx | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 540bd59cd5924..73a21797a35dd 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -231,11 +231,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.to_period PR01,SA01" \ -i "pandas.Timestamp.today SA01" \ -i "pandas.Timestamp.toordinal SA01" \ - -i "pandas.Timestamp.tz_localize SA01" \ -i "pandas.Timestamp.tzinfo GL08" \ - -i "pandas.Timestamp.tzname SA01" \ -i "pandas.Timestamp.unit SA01" \ - -i "pandas.Timestamp.utcfromtimestamp PR01,SA01" \ -i "pandas.Timestamp.utcoffset SA01" \ -i "pandas.Timestamp.utctimetuple SA01" \ -i "pandas.Timestamp.value GL08" \ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 6779c8e7f44b0..af3c07b8425a8 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1560,6 +1560,21 @@ class Timestamp(_Timestamp): Construct a timezone-aware UTC datetime from a POSIX timestamp. + This method creates a datetime object from a POSIX timestamp, keeping the Timestamp + object's timezone. + + Parameters + ---------- + ts : float + POSIX timestamp. + + See Also + -------- + Timezone.tzname : Return time zone name. + Timestamp.utcnow : Return a new Timestamp representing UTC day and time. + Timestamp.fromtimestamp : Transform timestamp[, tz] to tz's local + time from POSIX timestamp. + Notes ----- Timestamp.utcfromtimestamp behavior differs from datetime.utcfromtimestamp @@ -1735,6 +1750,13 @@ class Timestamp(_Timestamp): """ Return time zone name. + This method returns the name of the Timestamp's time zone as a string. + + See Also + -------- + Timestamp.tzinfo : Returns the timezone information of the Timestamp. + Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels') @@ -2468,6 +2490,13 @@ default 'raise' TypeError If the Timestamp is tz-aware and tz is not None. + See Also + -------- + Timestamp.tzinfo : Returns the timezone information of the Timestamp. + Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone. + DatetimeIndex.tz_localize : Localize a DatetimeIndex to a specific time zone. + datetime.datetime.astimezone : Convert a datetime object to another time zone. + Examples -------- Create a naive timestamp object: From 040689ac56a8b9c5c595d5a70dad0731901da9c6 Mon Sep 17 00:00:00 2001 From: MichaelMoyles Date: Sun, 11 Aug 2024 22:15:43 +0100 Subject: [PATCH 2/4] trimmed whitespace --- pandas/_libs/tslibs/timestamps.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index af3c07b8425a8..62d35a5367359 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1560,7 +1560,7 @@ class Timestamp(_Timestamp): Construct a timezone-aware UTC datetime from a POSIX timestamp. - This method creates a datetime object from a POSIX timestamp, keeping the Timestamp + This method creates a datetime object from a POSIX timestamp, keeping the Timestamp object's timezone. Parameters @@ -1572,7 +1572,7 @@ class Timestamp(_Timestamp): -------- Timezone.tzname : Return time zone name. Timestamp.utcnow : Return a new Timestamp representing UTC day and time. - Timestamp.fromtimestamp : Transform timestamp[, tz] to tz's local + Timestamp.fromtimestamp : Transform timestamp[, tz] to tz's local time from POSIX timestamp. Notes From 51def5bcd7ec5f28fe1c4d4b64ff9d4e3100eb50 Mon Sep 17 00:00:00 2001 From: MichaelMoyles Date: Sun, 11 Aug 2024 22:24:32 +0100 Subject: [PATCH 3/4] reducing line length --- pandas/_libs/tslibs/timestamps.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 62d35a5367359..0602884436270 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1560,8 +1560,8 @@ class Timestamp(_Timestamp): Construct a timezone-aware UTC datetime from a POSIX timestamp. - This method creates a datetime object from a POSIX timestamp, keeping the Timestamp - object's timezone. + This method creates a datetime object from a POSIX timestamp, keeping the + Timestamp object's timezone. Parameters ---------- From 6244320ccf05f7c0d52bdac2bb2ddd8f2d7bb034 Mon Sep 17 00:00:00 2001 From: MichaelMoyles Date: Mon, 12 Aug 2024 19:31:03 +0100 Subject: [PATCH 4/4] updating NaT docstrings to match for timestamps --- pandas/_libs/tslibs/nattype.pyx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 81b59578fe8c4..a0adffb4b2e26 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -626,6 +626,13 @@ class NaTType(_NaT): """ Return time zone name. + This method returns the name of the Timestamp's time zone as a string. + + See Also + -------- + Timestamp.tzinfo : Returns the timezone information of the Timestamp. + Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels') @@ -765,6 +772,21 @@ class NaTType(_NaT): Construct a timezone-aware UTC datetime from a POSIX timestamp. + This method creates a datetime object from a POSIX timestamp, keeping the + Timestamp object's timezone. + + Parameters + ---------- + ts : float + POSIX timestamp. + + See Also + -------- + Timezone.tzname : Return time zone name. + Timestamp.utcnow : Return a new Timestamp representing UTC day and time. + Timestamp.fromtimestamp : Transform timestamp[, tz] to tz's local + time from POSIX timestamp. + Notes ----- Timestamp.utcfromtimestamp behavior differs from datetime.utcfromtimestamp @@ -1432,6 +1454,13 @@ default 'raise' TypeError If the Timestamp is tz-aware and tz is not None. + See Also + -------- + Timestamp.tzinfo : Returns the timezone information of the Timestamp. + Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone. + DatetimeIndex.tz_localize : Localize a DatetimeIndex to a specific time zone. + datetime.datetime.astimezone : Convert a datetime object to another time zone. + Examples -------- Create a naive timestamp object: