From 62c19050541b3cc6d70f4b2880e68a42edf02ff8 Mon Sep 17 00:00:00 2001 From: Shubham Sarkar Date: Mon, 23 Jun 2025 22:35:37 +0530 Subject: [PATCH 1/5] FEAT: Added Create functionality to append mode of ExcelWriter when file doesn't exist --- pandas/io/excel/_base.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 1dc6c1f08b49a..fffca7891a081 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1254,6 +1254,11 @@ def __init__( ext = os.path.splitext(path)[-1] self.check_extension(ext) + # If file does not exist, and in append mode, switch to write mode. + if isinstance(path, str) and "a" in mode and not os.path.exists(path): + mode = mode.replace("a", "w") + if_sheet_exists = None + # use mode to open the file if "b" not in mode: mode += "b" From b81dd0ff0087e044232c9e0f254151fb3bb91316 Mon Sep 17 00:00:00 2001 From: Shubham Sarkar Date: Mon, 23 Jun 2025 22:40:06 +0530 Subject: [PATCH 2/5] FEAT: Added Create functionality to append mode of ExcelWriter when file doesn't exist --- pandas/io/excel/_base.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index fffca7891a081..1dc6c1f08b49a 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1254,11 +1254,6 @@ def __init__( ext = os.path.splitext(path)[-1] self.check_extension(ext) - # If file does not exist, and in append mode, switch to write mode. - if isinstance(path, str) and "a" in mode and not os.path.exists(path): - mode = mode.replace("a", "w") - if_sheet_exists = None - # use mode to open the file if "b" not in mode: mode += "b" From c28992249bdc31442f0ec4741e17dc097568ec57 Mon Sep 17 00:00:00 2001 From: Shubham Sarkar Date: Sat, 19 Jul 2025 19:36:30 +0530 Subject: [PATCH 3/5] docs: Fixed doctests in arrays/datetimelike.py --- pandas/core/arrays/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimelike.py b/pandas/core/arrays/datetimelike.py index 50fecc96f8186..d5e654c95577e 100644 --- a/pandas/core/arrays/datetimelike.py +++ b/pandas/core/arrays/datetimelike.py @@ -1778,7 +1778,7 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]: >>> rng.strftime("%%B %%d, %%Y, %%r") Index(['March 10, 2018, 09:00:00 AM', 'March 10, 2018, 09:00:01 AM', 'March 10, 2018, 09:00:02 AM'], - dtype='object') + dtype='str') """ result = self._format_native_types(date_format=date_format, na_rep=np.nan) if using_string_dtype(): From 91232025d398a3c20566fa876f196f2f955104d6 Mon Sep 17 00:00:00 2001 From: Shubham Sarkar Date: Sat, 19 Jul 2025 20:40:45 +0530 Subject: [PATCH 4/5] docs: Fixed doctests in arrays/datetimes.py --- pandas/core/arrays/datetimes.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index b31c543188282..57c138d9828bd 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1308,14 +1308,14 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: 0 January 1 February 2 March - dtype: object + dtype: str >>> idx = pd.date_range(start="2018-01", freq="ME", periods=3) >>> idx DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], dtype='datetime64[ns]', freq='ME') >>> idx.month_name() - Index(['January', 'February', 'March'], dtype='object') + Index(['January', 'February', 'March'], dtype='str') Using the ``locale`` parameter you can set a different locale language, for example: ``idx.month_name(locale='pt_BR.utf8')`` will return month @@ -1326,7 +1326,7 @@ def month_name(self, locale=None) -> npt.NDArray[np.object_]: DatetimeIndex(['2018-01-31', '2018-02-28', '2018-03-31'], dtype='datetime64[ns]', freq='ME') >>> idx.month_name(locale="pt_BR.utf8") # doctest: +SKIP - Index(['Janeiro', 'Fevereiro', 'Março'], dtype='object') + Index(['Janeiro', 'Fevereiro', 'Março'], dtype='str') """ values = self._local_timestamps() @@ -1376,14 +1376,14 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: 0 Monday 1 Tuesday 2 Wednesday - dtype: object + dtype: str >>> idx = pd.date_range(start="2018-01-01", freq="D", periods=3) >>> idx DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') >>> idx.day_name() - Index(['Monday', 'Tuesday', 'Wednesday'], dtype='object') + Index(['Monday', 'Tuesday', 'Wednesday'], dtype='str') Using the ``locale`` parameter you can set a different locale language, for example: ``idx.day_name(locale='pt_BR.utf8')`` will return day @@ -1394,7 +1394,7 @@ def day_name(self, locale=None) -> npt.NDArray[np.object_]: DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') >>> idx.day_name(locale="pt_BR.utf8") # doctest: +SKIP - Index(['Segunda', 'Terça', 'Quarta'], dtype='object') + Index(['Segunda', 'Terça', 'Quarta'], dtype='str') """ values = self._local_timestamps() From a4219c51552890d36da841cee7b603b8d218578e Mon Sep 17 00:00:00 2001 From: Shubham Sarkar Date: Sun, 20 Jul 2025 11:33:49 +0530 Subject: [PATCH 5/5] docs: Fixed doctests in indexes/datetimelike.py --- pandas/core/indexes/base.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 3efd601545212..e8c5a03a6de50 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1209,7 +1209,7 @@ def astype(self, dtype: Dtype, copy: bool = True): -------- >>> idx = pd.Index(['a', 'b', 'c']) >>> idx.take([2, 2, 1, 2]) - Index(['c', 'c', 'b', 'c'], dtype='object') + Index(['c', 'c', 'b', 'c'], dtype='str') """ @Appender(_index_shared_docs["take"] % _index_doc_kwargs) @@ -6862,11 +6862,11 @@ def delete( -------- >>> idx = pd.Index(["a", "b", "c"]) >>> idx.delete(1) - Index(['a', 'c'], dtype='object') + Index(['a', 'c'], dtype='str') >>> idx = pd.Index(["a", "b", "c"]) >>> idx.delete([0, 2]) - Index(['b'], dtype='object') + Index(['b'], dtype='str') """ values = self._values res_values: ArrayLike @@ -6906,7 +6906,7 @@ def insert(self, loc: int, item) -> Index: -------- >>> idx = pd.Index(["a", "b", "c"]) >>> idx.insert(1, "x") - Index(['a', 'x', 'b', 'c'], dtype='object') + Index(['a', 'x', 'b', 'c'], dtype='str') """ item = lib.item_from_zerodim(item) if is_valid_na_for_dtype(item, self.dtype) and self.dtype != object: