From e747c168a27ed853c6049ce0d92baafa8e6a4496 Mon Sep 17 00:00:00 2001 From: Lavishgangwani Date: Mon, 7 Oct 2024 11:43:31 +0530 Subject: [PATCH 1/2] Fix: Change None values to NaN in combine_first method for better handling of missing data --- pandas/core/series.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index bbcb6615aeefd..7c6599c93abbb 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3223,6 +3223,14 @@ def combine_first(self, other) -> Series: dtype: float64 """ from pandas.core.reshape.concat import concat + + # Change None values to NaN for both Series + def replace_none_with_nan(series): + series.fillna(value=np.nan, inplace=True) + + # Apply the function to both Series + replace_none_with_nan(self) + replace_none_with_nan(other) # Removed the extra parenthesis here if self.dtype == other.dtype: if self.index.equals(other.index): From 881f5231449177c656deac528e7f3be734482146 Mon Sep 17 00:00:00 2001 From: Lavishgangwani Date: Mon, 7 Oct 2024 13:02:38 +0530 Subject: [PATCH 2/2] Refactor: Clean up comments and improve function documentation in Series class --- pandas/core/series.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 7c6599c93abbb..1be74df8c9ac3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -3223,14 +3223,13 @@ def combine_first(self, other) -> Series: dtype: float64 """ from pandas.core.reshape.concat import concat - - # Change None values to NaN for both Series + def replace_none_with_nan(series): series.fillna(value=np.nan, inplace=True) - # Apply the function to both Series + """Apply the function to both Series""" replace_none_with_nan(self) - replace_none_with_nan(other) # Removed the extra parenthesis here + replace_none_with_nan(other) if self.dtype == other.dtype: if self.index.equals(other.index):