diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index fea50b3b7f75d3..f1d72673afe214 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -133,7 +133,7 @@ def test_nunique_empty(self): tm.assert_series_equal(result, expected) result = df.T.nunique() - expected = Series([], index=pd.Index([])) + expected = Series(index=pd.Index([]), dtype=np.float64) tm.assert_series_equal(result, expected) def test_apply_standard_nonunique(self): @@ -1265,16 +1265,16 @@ def test_non_callable_aggregates(self): _get_cython_table_params( DataFrame(), [ - ("sum", Series()), - ("max", Series()), - ("min", Series()), + ("sum", Series(dtype="float64")), + ("max", Series(dtype="float64")), + ("min", Series(dtype="float64")), ("all", Series(dtype=bool)), ("any", Series(dtype=bool)), - ("mean", Series()), - ("prod", Series()), - ("std", Series()), - ("var", Series()), - ("median", Series()), + ("mean", Series(dtype="float64")), + ("prod", Series(dtype="float64")), + ("std", Series(dtype="float64")), + ("var", Series(dtype="float64")), + ("median", Series(dtype="float64")), ], ), _get_cython_table_params( diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index aa00cf234d9ee6..8dbf3252456f8e 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -2442,7 +2442,7 @@ def test_from_records_series_list_dict(self): def test_to_frame_with_falsey_names(self): # GH 16114 result = Series(name=0).to_frame().dtypes - expected = Series({0: np.float64}) + expected = Series({0: object}) tm.assert_series_equal(result, expected) result = DataFrame(Series(name=0)).dtypes diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index e215c90d2eb040..86f97c139849cf 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -2574,7 +2574,9 @@ def test_xs_corner(self): # no columns but Index(dtype=object) df = DataFrame(index=["a", "b", "c"]) result = df.xs("a") - expected = Series([], name="a", index=pd.Index([], dtype=object)) + expected = Series( + [], name="a", index=pd.Index([], dtype=object), dtype="float64" + ) tm.assert_series_equal(result, expected) def test_xs_duplicates(self): diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index c180511e316199..6687c965071c62 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -734,11 +734,8 @@ def test_squeeze(self): # don't fail with 0 length dimensions GH11229 & GH8999 empty_series = Series([], name="five") empty_frame = DataFrame([empty_series]) - - [ - tm.assert_series_equal(empty_series, higher_dim.squeeze()) - for higher_dim in [empty_series, empty_frame] - ] + tm.assert_series_equal(empty_series, empty_series.squeeze()) + tm.assert_series_equal(empty_series, empty_frame.squeeze()) # axis argument df = tm.makeTimeDataFrame(nper=1).iloc[:, :1] diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index e4edc640165676..b7941ecef8350c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -602,7 +602,7 @@ def test_evaluate_with_empty_groups(self, func, expected): def test_groupby_empty(self): # https://github.com/pandas-dev/pandas/issues/27190 - s = pd.Series([], name="name") + s = pd.Series(name="name", dtype="float64") gr = s.groupby([]) result = gr.mean() diff --git a/pandas/tests/indexing/multiindex/test_loc.py b/pandas/tests/indexing/multiindex/test_loc.py index 9eeee897bfbb5f..512dfceb5c4ed7 100644 --- a/pandas/tests/indexing/multiindex/test_loc.py +++ b/pandas/tests/indexing/multiindex/test_loc.py @@ -50,7 +50,9 @@ def test_loc_getitem_series(self): empty = Series(data=[], dtype=np.float64) expected = Series( - [], index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64) + [], + index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64), + dtype=np.float64, ) result = x.loc[empty] tm.assert_series_equal(result, expected) @@ -72,7 +74,9 @@ def test_loc_getitem_array(self): # empty array: empty = np.array([]) expected = Series( - [], index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64) + [], + index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64), + dtype="float64", ) result = x.loc[empty] tm.assert_series_equal(result, expected) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index d31aa04b223e8a..be1fef9d4f42f2 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -670,7 +670,7 @@ def test_series_roundtrip_object(self, orient, numpy, dtype): def test_series_roundtrip_empty(self, orient, numpy): data = self.empty_series.to_json(orient=orient) result = pd.read_json(data, typ="series", orient=orient, numpy=numpy) - expected = self.empty_series.copy() + expected = self.empty_series.copy().astype("float64") # TODO: see what causes inconsistency if orient in ("values", "records"): diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index 4dfe561831ced0..26c5f07d4b9f66 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -900,7 +900,7 @@ def test_timedelta64_analytics(self): @pytest.mark.parametrize( "test_input,error_type", [ - (pd.Series([]), ValueError), + (pd.Series(dtype="float64"), ValueError), # For strings, or any Series with dtype 'O' (pd.Series(["foo", "bar", "baz"]), TypeError), (pd.Series([(1,), (2,)]), TypeError), diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index 5c930e01c735d9..8535f17668dea0 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -2196,7 +2196,7 @@ def test_concat_period_other_series(self): def test_concat_empty_series(self): # GH 11082 s1 = pd.Series([1, 2, 3], name="x") - s2 = pd.Series(name="y") + s2 = pd.Series(name="y", dtype="float64") res = pd.concat([s1, s2], axis=1) exp = pd.DataFrame( {"x": [1, 2, 3], "y": [np.nan, np.nan, np.nan]}, @@ -2205,7 +2205,7 @@ def test_concat_empty_series(self): tm.assert_frame_equal(res, exp) s1 = pd.Series([1, 2, 3], name="x") - s2 = pd.Series(name="y") + s2 = pd.Series(name="y", dtype="float64") res = pd.concat([s1, s2], axis=0) # name will be reset exp = pd.Series([1, 2, 3]) @@ -2213,7 +2213,7 @@ def test_concat_empty_series(self): # empty Series with no name s1 = pd.Series([1, 2, 3], name="x") - s2 = pd.Series(name=None) + s2 = pd.Series(name=None, dtype="float64") res = pd.concat([s1, s2], axis=1) exp = pd.DataFrame( {"x": [1, 2, 3], 0: [np.nan, np.nan, np.nan]}, @@ -2228,7 +2228,7 @@ def test_concat_empty_series_timelike(self, tz, values): # GH 18447 first = Series([], dtype="M8[ns]").dt.tz_localize(tz) - second = Series(values) + second = Series(values, dtype="float64") expected = DataFrame( { 0: pd.Series([pd.NaT] * len(values), dtype="M8[ns]").dt.tz_localize(tz), diff --git a/pandas/tests/window/test_moments.py b/pandas/tests/window/test_moments.py index 36a0ddb3e02d71..f4b9a57049c625 100644 --- a/pandas/tests/window/test_moments.py +++ b/pandas/tests/window/test_moments.py @@ -674,7 +674,7 @@ def f(x): self._check_moment_func(np.mean, name="apply", func=f, raw=raw) - expected = Series([]) + expected = Series(dtype="float64") result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw) tm.assert_series_equal(result, expected) @@ -1201,7 +1201,7 @@ def _check_ew(self, name=None, preserve_nan=False): # check series of length 0 result = getattr(Series().ewm(com=50, min_periods=min_periods), name)() - tm.assert_series_equal(result, Series()) + tm.assert_series_equal(result, Series(dtype="float64")) # check series of length 1 result = getattr(Series([1.0]).ewm(50, min_periods=min_periods), name)() @@ -1996,8 +1996,8 @@ def func(A, B, com, **kwargs): assert not np.isnan(result.values[11:]).any() # check series of length 0 - result = func(Series([]), Series([]), 50, min_periods=min_periods) - tm.assert_series_equal(result, Series([])) + result = func(Series(), Series(), 50, min_periods=min_periods) + tm.assert_series_equal(result, Series(dtype="float64")) # check series of length 1 result = func(Series([1.0]), Series([1.0]), 50, min_periods=min_periods) @@ -2197,7 +2197,7 @@ def test_rolling_functions_window_non_shrinkage_binary(self): def test_moment_functions_zero_length(self): # GH 8056 - s = Series() + s = Series(dtype="float64") s_expected = s df1 = DataFrame() df1_expected = df1 @@ -2416,7 +2416,7 @@ def expanding_mean(x, min_periods=1): # here to make this pass self._check_expanding(expanding_mean, np.mean, preserve_nan=False) - ser = Series([]) + ser = Series([], dtype="float64") tm.assert_series_equal(ser, ser.expanding().apply(lambda x: x.mean(), raw=raw)) # GH 8080