From d8ba24d4bc1c6d92f99f727c1287bf0e8a1de050 Mon Sep 17 00:00:00 2001 From: David Kunzmann Date: Tue, 30 Jan 2024 16:07:05 +0100 Subject: [PATCH] Fix backquotes --- rules/S6884/python/rule.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/S6884/python/rule.adoc b/rules/S6884/python/rule.adoc index 70427347346..3b2da9a6a92 100644 --- a/rules/S6884/python/rule.adoc +++ b/rules/S6884/python/rule.adoc @@ -28,7 +28,7 @@ pd.to_datetime(['2020-10-25 02:00 +0200', '2020-10-25 04:00 +0100']) # mixed tim # returns Index([2020-10-25 02:00:00+02:00, 2020-10-25 04:00:00+01:00], dtype='object') ---- -When processing `datetime`s with mixed offsets, `pandas.to_datetime` will not succeed in creating a +When processing ``datetime``s with mixed offsets, `pandas.to_datetime` will not succeed in creating a `DatetimeIndex` instead it will create an `Index` of `object`. Working with dates with different timezones can lead to bugs, for example when comparing these dates. @@ -44,7 +44,7 @@ pd.to_datetime(['2018-10-26 12:00 -0530', '2018-10-26 12:00 -0500'], utc=True) # returns DatetimeIndex(['2018-10-26 17:30:00+00:00', '2018-10-26 17:00:00+00:00'], dtype='datetime64[ns, UTC]', freq=None) ---- -If however the intent is to create a `Series` containing `datetime`s with mixed offsets, +If however the intent is to create a `Series` containing ``datetime``s with mixed offsets, the recommended way would be to use `apply` and `datetime.datetime.strptime`. == How to fix it @@ -61,7 +61,7 @@ import pandas as pd pd.to_datetime(['2018-10-26 12:00:00']) # Noncompliant: utc defaults to False -pd.to_datetime(['2018-10-26 12:00 -0530', '2018-10-26 12:00 -0500'], utc=False) # Noncompliant: to create a `Series` containing `datetime`s with mixed offsets, +pd.to_datetime(['2018-10-26 12:00 -0530', '2018-10-26 12:00 -0500'], utc=False) # Noncompliant: to create a `Series` containing ``datetime``s with mixed offsets, # use `apply` and `datetime.datetime.strptime` instead ----