From de49e43ebe089a8a8b3e1d30e00f07a999264707 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Wed, 11 Aug 2021 00:25:17 -0700 Subject: [PATCH 01/12] TST GH#40498 Add tests for fillna other missing values not modified. --- pandas/tests/frame/methods/test_fillna.py | 22 ++++++++++++++++++++++ pandas/tests/series/methods/test_fillna.py | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index b1ce511fc3e4c..0d0f47d58461b 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -153,6 +153,28 @@ def test_fillna_tzaware_different_column(self): ) tm.assert_frame_equal(result, expected) + def test_other_missing_values_not_modified( + self, unique_nulls_fixture, unique_nulls_fixture2 + ): + # GH#40498 + df = DataFrame( + { + "A": [1, unique_nulls_fixture, unique_nulls_fixture2, "four"], + "B": [2, unique_nulls_fixture, unique_nulls_fixture2, "eight"], + } + ) + value = {"A": {1: 0}, "B": {2: 0}} + result = df.fillna(value) + + expected = DataFrame( + { + "A": [1, 0, unique_nulls_fixture2, "four"], + "B": [2, unique_nulls_fixture, 0, "eight"], + } + ) + + tm.assert_frame_equal(result, expected) + def test_na_actions_categorical(self): cat = Categorical([1, 2, 3, np.nan], categories=[1, 2, 3]) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 03e126587ce1a..53fcf47f47aa4 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -623,6 +623,19 @@ def test_fillna_numeric_inplace(self): expected = x.fillna(value=0) tm.assert_series_equal(y, expected) + def test_fillna_other_missing_values_not_modified( + self, unique_nulls_fixture, unique_nulls_fixture2 + ): + # GH#40498 + ser = Series([1, unique_nulls_fixture, unique_nulls_fixture2, "four"]) + + value = {2: 0} + result = ser.fillna(value) + + expected = Series([1, unique_nulls_fixture, 0, "four"]) + + tm.assert_series_equal(result, expected) + # --------------------------------------------------------------- # CategoricalDtype From 839fafbe46729d2d8cd6a3dc2d928f8212c0f2c1 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Wed, 11 Aug 2021 00:51:52 -0700 Subject: [PATCH 02/12] TST GH#40498 Add tests for fillna null value replacement. --- pandas/tests/frame/methods/test_fillna.py | 20 ++++++++++++++++++++ pandas/tests/series/methods/test_fillna.py | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 0d0f47d58461b..71452960eab0c 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -153,6 +153,26 @@ def test_fillna_tzaware_different_column(self): ) tm.assert_frame_equal(result, expected) + def test_null_value_replacement(self): + # GH$40498 + df = DataFrame( + { + "A": [1, 2, None, 4], + "B": [2, None, 6, 8], + } + ) + value = np.nan + result = df.fillna(value) + + expected = DataFrame( + { + "A": [1, 2, np.nan, 4], + "B": [2, np.nan, 6, 8], + } + ) + + tm.assert_frame_equal(result, expected) + def test_other_missing_values_not_modified( self, unique_nulls_fixture, unique_nulls_fixture2 ): diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 53fcf47f47aa4..c00fd6d4ff7ac 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -623,6 +623,17 @@ def test_fillna_numeric_inplace(self): expected = x.fillna(value=0) tm.assert_series_equal(y, expected) + def test_fillna_null_value_replacement(self): + # GH#40498 + ser = Series([None]) + + value = np.nan + result = ser.fillna(value) + + expected = Series([np.nan]) + + tm.assert_series_equal(result, expected) + def test_fillna_other_missing_values_not_modified( self, unique_nulls_fixture, unique_nulls_fixture2 ): From 0cbbcde7dc613b6b0a05f847b882466a5c31366e Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Wed, 11 Aug 2021 01:00:33 -0700 Subject: [PATCH 03/12] BUG GH#40498 Create fillna values to use original mapped by new values. --- pandas/core/generic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 860d4f6a5dcc2..98be07747a657 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6275,11 +6275,13 @@ def fillna( else: if self.ndim == 1: if isinstance(value, (dict, ABCSeries)): - value = create_series_with_explicit_dtype( + value_map = create_series_with_explicit_dtype( value, dtype_if_empty=object ) - value = value.reindex(self.index, copy=False) - value = value._values + value = self.copy() + modification_index = value.index.intersection(value_map.index) + if not modification_index.empty: + value.loc[modification_index] = value_map[modification_index] elif not is_list_like(value): pass else: From 1887872a20353a46892d2880919dbcee33e66844 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Thu, 26 Aug 2021 23:16:21 -0700 Subject: [PATCH 04/12] TST GH#40498 Add benchmark tests for fillna using value. --- asv_bench/benchmarks/frame_methods.py | 16 ++++++---- asv_bench/benchmarks/series_methods.py | 44 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index e5834f311d259..f02ace93832db 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -374,7 +374,7 @@ class Fillna: params = ( [True, False], - ["pad", "bfill"], + [None, "pad", "bfill"], [ "float64", "float32", @@ -400,15 +400,19 @@ def setup(self, inplace, method, dtype): } self.df = DataFrame({f"col_{i}": data[dtype] for i in range(M)}) self.df[::2] = None + self.value = ( + dict(zip(self.df.columns, data[dtype][:M])) if not method else None + ) else: - values = np.random.randn(N, M) - values[::2] = np.nan + data = np.random.randn(N, M) if dtype == "Int64": - values = values.round() - self.df = DataFrame(values, dtype=dtype) + data = data.round() + self.df = DataFrame({f"col_{i}": data[i] for i in range(M)}) + self.df[::2] = None + self.value = dict(zip(self.df.columns, data[M])) if not method else None def time_frame_fillna(self, inplace, method, dtype): - self.df.fillna(inplace=inplace, method=method) + self.df.fillna(value=self.value, inplace=inplace, method=method) class Dropna: diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index 7592ce54e3712..e42ffe5d0cc90 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -6,6 +6,7 @@ NaT, Series, date_range, + timedelta_range, ) from .pandas_vb_common import tm @@ -42,6 +43,49 @@ def time_nsmallest(self, keep): self.s.nsmallest(3, keep=keep) +class Fillna: + + params = ( + [True, False], + [None, "pad", "bfill"], + [ + "float64", + "float32", + "object", + "Int64", + "Float64", + "datetime64[ns]", + "datetime64[ns, tz]", + "timedelta64[ns]", + ], + ) + param_names = ["inplace", "method", "dtype"] + + def setup(self, inplace, method, dtype): + N = 10000 + if dtype in ("datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]"): + data = { + "datetime64[ns]": date_range("2011-01-01", freq="H", periods=N), + "datetime64[ns, tz]": date_range( + "2011-01-01", freq="H", periods=N, tz="Asia/Tokyo" + ), + "timedelta64[ns]": timedelta_range(start="1 day", periods=N, freq="1D"), + } + self.ser = Series(data[dtype]) + self.ser[::2] = None + self.value = dict(zip(self.ser.index, data[dtype])) if not method else None + else: + data = np.random.randn(N) + if dtype == "Int64": + data = data.round() + self.ser = Series(data, dtype=dtype) + self.ser[::2] = None + self.value = dict(zip(self.ser.index, data)) if not method else None + + def time_series_fillna(self, inplace, method, dtype): + self.ser.fillna(value=self.value, inplace=inplace, method=method) + + class Dropna: params = ["int", "datetime"] From c1fc30741cdf004cec239fede85b4cbe561b6147 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Thu, 26 Aug 2021 23:48:02 -0700 Subject: [PATCH 05/12] BUG GH#40498 Add conditional for object dtype to avoid performance decrease. --- pandas/core/generic.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 98be07747a657..cc7e9dbab543c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6278,10 +6278,17 @@ def fillna( value_map = create_series_with_explicit_dtype( value, dtype_if_empty=object ) - value = self.copy() - modification_index = value.index.intersection(value_map.index) - if not modification_index.empty: - value.loc[modification_index] = value_map[modification_index] + if self.dtype == "object": + value = self.copy() + modification_index = value.index.intersection(value_map.index) + if not modification_index.empty: + value.loc[modification_index] = value_map[ + modification_index + ] + else: + value = value_map + value = value.reindex(self.index, copy=False) + value = value._values elif not is_list_like(value): pass else: From 1ea7d1d964efdbff66920a9b2d00ad327a90183c Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Sun, 5 Sep 2021 17:52:07 -0700 Subject: [PATCH 06/12] TST GH#40498 Clean up fillna benchmark tests. --- asv_bench/benchmarks/frame_methods.py | 11 +++++------ asv_bench/benchmarks/series_methods.py | 11 +++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index 37b1d52bad887..391f4e89a9bb0 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -376,11 +376,11 @@ class Fillna: [True, False], [None, "pad", "bfill"], [ - "float64", - "float32", "object", - "Int64", - "Float64", + "int32", + "int64", + "float32", + "float64", "datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]", @@ -405,8 +405,7 @@ def setup(self, inplace, method, dtype): ) else: data = np.random.randn(N, M) - if dtype == "Int64": - data = data.round() + data = data.astype(dtype) self.df = DataFrame({f"col_{i}": data[i] for i in range(M)}) self.df[::2] = None self.value = dict(zip(self.df.columns, data[M])) if not method else None diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index e42ffe5d0cc90..2c85df38c1544 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -49,11 +49,11 @@ class Fillna: [True, False], [None, "pad", "bfill"], [ - "float64", - "float32", "object", - "Int64", - "Float64", + "int32", + "int64", + "float32", + "float64", "datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]", @@ -76,8 +76,7 @@ def setup(self, inplace, method, dtype): self.value = dict(zip(self.ser.index, data[dtype])) if not method else None else: data = np.random.randn(N) - if dtype == "Int64": - data = data.round() + data = data.astype(dtype) self.ser = Series(data, dtype=dtype) self.ser[::2] = None self.value = dict(zip(self.ser.index, data)) if not method else None From 20bea4e57adfd9abd7112e8ff6a55091b99f4eb2 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Mon, 6 Sep 2021 10:32:45 -0700 Subject: [PATCH 07/12] BUG GH#40498 Add comment and cleanup logic for special case. --- pandas/core/generic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7acb1c650e312..06413bdc4f799 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6311,7 +6311,10 @@ def fillna( value_map = create_series_with_explicit_dtype( value, dtype_if_empty=object ) - if self.dtype == "object": + # GH#40498 objects can have multiple types of missing values which should not be modified unless + # specified. Add special casing to minimize performance decrease on other data types where this is + # not required. + if is_object_dtype(self.dtype): value = self.copy() modification_index = value.index.intersection(value_map.index) if not modification_index.empty: @@ -6319,8 +6322,7 @@ def fillna( modification_index ] else: - value = value_map - value = value.reindex(self.index, copy=False) + value = value_map.reindex(self.index, copy=False) value = value._values elif not is_list_like(value): pass From 8249829db21d5d9cc7a2ae01d64deecbecd8dbc9 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Mon, 6 Sep 2021 10:55:21 -0700 Subject: [PATCH 08/12] TST GH#40498 Use frame_or_series to consolidate new fillna tests. --- pandas/tests/frame/methods/test_fillna.py | 42 ---------------------- pandas/tests/series/methods/test_fillna.py | 23 +++++++----- 2 files changed, 14 insertions(+), 51 deletions(-) diff --git a/pandas/tests/frame/methods/test_fillna.py b/pandas/tests/frame/methods/test_fillna.py index 7abbc7962a68b..56b0029b49779 100644 --- a/pandas/tests/frame/methods/test_fillna.py +++ b/pandas/tests/frame/methods/test_fillna.py @@ -153,48 +153,6 @@ def test_fillna_tzaware_different_column(self): ) tm.assert_frame_equal(result, expected) - def test_null_value_replacement(self): - # GH$40498 - df = DataFrame( - { - "A": [1, 2, None, 4], - "B": [2, None, 6, 8], - } - ) - value = np.nan - result = df.fillna(value) - - expected = DataFrame( - { - "A": [1, 2, np.nan, 4], - "B": [2, np.nan, 6, 8], - } - ) - - tm.assert_frame_equal(result, expected) - - def test_other_missing_values_not_modified( - self, unique_nulls_fixture, unique_nulls_fixture2 - ): - # GH#40498 - df = DataFrame( - { - "A": [1, unique_nulls_fixture, unique_nulls_fixture2, "four"], - "B": [2, unique_nulls_fixture, unique_nulls_fixture2, "eight"], - } - ) - value = {"A": {1: 0}, "B": {2: 0}} - result = df.fillna(value) - - expected = DataFrame( - { - "A": [1, 0, unique_nulls_fixture2, "four"], - "B": [2, unique_nulls_fixture, 0, "eight"], - } - ) - - tm.assert_frame_equal(result, expected) - def test_na_actions_categorical(self): cat = Categorical([1, 2, 3, np.nan], categories=[1, 2, 3]) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index c00fd6d4ff7ac..322759be93e26 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -623,29 +623,34 @@ def test_fillna_numeric_inplace(self): expected = x.fillna(value=0) tm.assert_series_equal(y, expected) - def test_fillna_null_value_replacement(self): + def test_fillna_null_value_replacement(self, frame_or_series): # GH#40498 - ser = Series([None]) + ser = Series([None, None]) + obj = frame_or_series(ser) value = np.nan - result = ser.fillna(value) + result = obj.fillna(value) - expected = Series([np.nan]) + expected = Series([np.nan, np.nan]) + expected = frame_or_series(expected) - tm.assert_series_equal(result, expected) + tm.assert_equal(result, expected) def test_fillna_other_missing_values_not_modified( - self, unique_nulls_fixture, unique_nulls_fixture2 + self, unique_nulls_fixture, unique_nulls_fixture2, frame_or_series ): # GH#40498 ser = Series([1, unique_nulls_fixture, unique_nulls_fixture2, "four"]) + obj = frame_or_series(ser) - value = {2: 0} - result = ser.fillna(value) + value = {2: 0} if frame_or_series is Series else {0: {2: 0}} + + result = obj.fillna(value) expected = Series([1, unique_nulls_fixture, 0, "four"]) + expected = frame_or_series(expected) - tm.assert_series_equal(result, expected) + tm.assert_equal(result, expected) # --------------------------------------------------------------- # CategoricalDtype From 09b195ab9b9a6e1f4f50d98aec667c5693bb311e Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Mon, 6 Sep 2021 11:00:02 -0700 Subject: [PATCH 09/12] BUG GH#40498 Fix comment line-length to 88 characters. --- pandas/core/generic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b0e8993869007..bab633646553c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6311,8 +6311,9 @@ def fillna( value_map = create_series_with_explicit_dtype( value, dtype_if_empty=object ) - # GH#40498 objects can have multiple types of missing values which should not be modified unless - # specified. Add special casing to minimize performance decrease on other data types where this is + # GH#40498 objects can have multiple types of missing values which + # should not be modified unless specified. Add special casing to + # minimize performance decrease on other data types where this is # not required. if is_object_dtype(self.dtype): value = self.copy() From bc3aa8d8166b29d809c2e5864fa3add8fb672b76 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Mon, 6 Sep 2021 17:03:56 -0700 Subject: [PATCH 10/12] CLN GH#40498 Remove unecessary copy=False argument from reindex. --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bab633646553c..d06e9bb9f3226 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6323,7 +6323,7 @@ def fillna( modification_index ] else: - value = value_map.reindex(self.index, copy=False) + value = value_map.reindex(self.index) value = value._values elif not is_list_like(value): pass From 0af57f1340f755de9a9a5a3a94121a4e19879295 Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Mon, 6 Sep 2021 18:00:23 -0700 Subject: [PATCH 11/12] TST GH#40498 Expand test_fillna_object_null_value_replacement for unique null fixtures. --- pandas/tests/series/methods/test_fillna.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/methods/test_fillna.py b/pandas/tests/series/methods/test_fillna.py index 322759be93e26..a96f697a7f0eb 100644 --- a/pandas/tests/series/methods/test_fillna.py +++ b/pandas/tests/series/methods/test_fillna.py @@ -623,20 +623,26 @@ def test_fillna_numeric_inplace(self): expected = x.fillna(value=0) tm.assert_series_equal(y, expected) - def test_fillna_null_value_replacement(self, frame_or_series): + def test_fillna_object_null_value_replacement( + self, frame_or_series, unique_nulls_fixture, unique_nulls_fixture2 + ): # GH#40498 - ser = Series([None, None]) + ser = Series([1, unique_nulls_fixture, "three"]) obj = frame_or_series(ser) - value = np.nan + if unique_nulls_fixture2 is not None: + value = unique_nulls_fixture2 + else: + pytest.skip(f"{unique_nulls_fixture2} cannot be passed to fillna.") + result = obj.fillna(value) - expected = Series([np.nan, np.nan]) + expected = Series([1, unique_nulls_fixture2, "three"]) expected = frame_or_series(expected) tm.assert_equal(result, expected) - def test_fillna_other_missing_values_not_modified( + def test_fillna_object_other_missing_values_not_modified( self, unique_nulls_fixture, unique_nulls_fixture2, frame_or_series ): # GH#40498 From 4229a70bc230b08390633769f9515c736b70563a Mon Sep 17 00:00:00 2001 From: Mike Phung Date: Wed, 29 Sep 2021 22:14:40 -0700 Subject: [PATCH 12/12] TST GH#40498 Return Int64 and Float64 to asv benchmark and update setups. --- asv_bench/benchmarks/frame_methods.py | 19 ++++++++++++++----- asv_bench/benchmarks/series_methods.py | 13 ++++++++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/asv_bench/benchmarks/frame_methods.py b/asv_bench/benchmarks/frame_methods.py index 391f4e89a9bb0..21b82c8302eb9 100644 --- a/asv_bench/benchmarks/frame_methods.py +++ b/asv_bench/benchmarks/frame_methods.py @@ -379,8 +379,10 @@ class Fillna: "object", "int32", "int64", + "Int64", "float32", "float64", + "Float64", "datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]", @@ -399,16 +401,23 @@ def setup(self, inplace, method, dtype): "timedelta64[ns]": timedelta_range(start="1 day", periods=N, freq="1D"), } self.df = DataFrame({f"col_{i}": data[dtype] for i in range(M)}) - self.df[::2] = None self.value = ( - dict(zip(self.df.columns, data[dtype][:M])) if not method else None + dict(zip(self.df.columns, self.df.sample().iloc[0])) + if not method + else None ) + self.df[::2] = None else: data = np.random.randn(N, M) - data = data.astype(dtype) - self.df = DataFrame({f"col_{i}": data[i] for i in range(M)}) + if dtype in ["int32", "int64", "Int64"]: + data = data.round() + self.df = DataFrame({f"col_{i}": data[i] for i in range(M)}, dtype=dtype) + self.value = ( + dict(zip(self.df.columns, self.df.sample().iloc[0])) + if not method + else None + ) self.df[::2] = None - self.value = dict(zip(self.df.columns, data[M])) if not method else None def time_frame_fillna(self, inplace, method, dtype): self.df.fillna(value=self.value, inplace=inplace, method=method) diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index 3ab0a2be102cb..133bca2ede107 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -65,8 +65,10 @@ class Fillna: "object", "int32", "int64", + "Int64", "float32", "float64", + "Float64", "datetime64[ns]", "datetime64[ns, tz]", "timedelta64[ns]", @@ -85,14 +87,19 @@ def setup(self, inplace, method, dtype): "timedelta64[ns]": timedelta_range(start="1 day", periods=N, freq="1D"), } self.ser = Series(data[dtype]) + self.value = ( + dict(zip(self.ser.index, self.ser.values)) if not method else None + ) self.ser[::2] = None - self.value = dict(zip(self.ser.index, data[dtype])) if not method else None else: data = np.random.randn(N) - data = data.astype(dtype) + if dtype in ["int32", "int64", "Int64"]: + data = data.round() self.ser = Series(data, dtype=dtype) + self.value = ( + dict(zip(self.ser.index, self.ser.values)) if not method else None + ) self.ser[::2] = None - self.value = dict(zip(self.ser.index, data)) if not method else None def time_series_fillna(self, inplace, method, dtype): self.ser.fillna(value=self.value, inplace=inplace, method=method)