diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a50a71bbbad63..ab44598e04440 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -37,6 +37,12 @@ function invgrep { return $((! $EXIT_STATUS)) } +function check_namespace { + local -r CLASS="${1}" + grep -R -l --include "*.py" " ${CLASS}(" pandas/tests | xargs grep -n "pd\.${CLASS}(" + test $? -gt 0 +} + if [[ "$GITHUB_ACTIONS" == "true" ]]; then FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s" INVGREP_PREPEND="##[error]" @@ -195,6 +201,11 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then MSG='Check code for instances of os.remove' ; echo $MSG invgrep -R --include="*.py*" --exclude "common.py" --exclude "test_writers.py" --exclude "test_store.py" -E "os\.remove" pandas/tests/ RET=$(($RET + $?)) ; echo $MSG "DONE" + + MSG='Check for inconsistent use of pandas namespace in tests' ; echo $MSG + check_namespace "Series" + RET=$(($RET + $?)) + echo $MSG "DONE" fi ### CODE ### diff --git a/pandas/tests/arithmetic/test_datetime64.py b/pandas/tests/arithmetic/test_datetime64.py index c0ae36017f47a..f9dd4a7445a99 100644 --- a/pandas/tests/arithmetic/test_datetime64.py +++ b/pandas/tests/arithmetic/test_datetime64.py @@ -140,11 +140,11 @@ def test_dt64arr_nat_comparison(self, tz_naive_fixture, box_with_array): xbox = box if box not in [pd.Index, pd.array] else np.ndarray ts = pd.Timestamp.now(tz) - ser = pd.Series([ts, pd.NaT]) + ser = Series([ts, pd.NaT]) obj = tm.box_expected(ser, box) - expected = pd.Series([True, False], dtype=np.bool_) + expected = Series([True, False], dtype=np.bool_) expected = tm.box_expected(expected, xbox) result = obj == ts @@ -278,7 +278,7 @@ def test_series_comparison_scalars(self, val): def test_timestamp_compare_series(self, left, right): # see gh-4982 # Make sure we can compare Timestamps on the right AND left hand side. - ser = pd.Series(pd.date_range("20010101", periods=10), name="dates") + ser = Series(pd.date_range("20010101", periods=10), name="dates") s_nat = ser.copy(deep=True) ser[0] = pd.Timestamp("nat") @@ -313,7 +313,7 @@ def test_dt64arr_timestamp_equality(self, box_with_array): box_with_array if box_with_array not in [pd.Index, pd.array] else np.ndarray ) - ser = pd.Series([pd.Timestamp("2000-01-29 01:59:00"), "NaT"]) + ser = Series([pd.Timestamp("2000-01-29 01:59:00"), "NaT"]) ser = tm.box_expected(ser, box_with_array) result = ser != ser @@ -973,7 +973,7 @@ def test_dt64arr_sub_timestamp(self, box_with_array): ser = tm.box_expected(ser, box_with_array) - delta_series = pd.Series([np.timedelta64(0, "D"), np.timedelta64(1, "D")]) + delta_series = Series([np.timedelta64(0, "D"), np.timedelta64(1, "D")]) expected = tm.box_expected(delta_series, box_with_array) tm.assert_equal(ser - ts, expected) @@ -985,7 +985,7 @@ def test_dt64arr_sub_NaT(self, box_with_array): ser = tm.box_expected(dti, box_with_array) result = ser - pd.NaT - expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]") + expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]") expected = tm.box_expected(expected, box_with_array) tm.assert_equal(result, expected) @@ -993,7 +993,7 @@ def test_dt64arr_sub_NaT(self, box_with_array): ser_tz = tm.box_expected(dti_tz, box_with_array) result = ser_tz - pd.NaT - expected = pd.Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]") + expected = Series([pd.NaT, pd.NaT], dtype="timedelta64[ns]") expected = tm.box_expected(expected, box_with_array) tm.assert_equal(result, expected) @@ -1606,7 +1606,7 @@ def test_dt64_series_arith_overflow(self): dt = pd.Timestamp("1700-01-31") td = pd.Timedelta("20000 Days") dti = pd.date_range("1949-09-30", freq="100Y", periods=4) - ser = pd.Series(dti) + ser = Series(dti) msg = "Overflow in int64 addition" with pytest.raises(OverflowError, match=msg): ser - dt @@ -1618,7 +1618,7 @@ def test_dt64_series_arith_overflow(self): td + ser ser.iloc[-1] = pd.NaT - expected = pd.Series( + expected = Series( ["2004-10-03", "2104-10-04", "2204-10-04", "NaT"], dtype="datetime64[ns]" ) res = ser + td @@ -1627,9 +1627,7 @@ def test_dt64_series_arith_overflow(self): tm.assert_series_equal(res, expected) ser.iloc[1:] = pd.NaT - expected = pd.Series( - ["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]" - ) + expected = Series(["91279 Days", "NaT", "NaT", "NaT"], dtype="timedelta64[ns]") res = ser - dt tm.assert_series_equal(res, expected) res = dt - ser @@ -1830,8 +1828,8 @@ def test_dt64tz_series_sub_dtitz(self): # GH#19071 subtracting tzaware DatetimeIndex from tzaware Series # (with same tz) raises, fixed by #19024 dti = pd.date_range("1999-09-30", periods=10, tz="US/Pacific") - ser = pd.Series(dti) - expected = pd.Series(pd.TimedeltaIndex(["0days"] * 10)) + ser = Series(dti) + expected = Series(pd.TimedeltaIndex(["0days"] * 10)) res = dti - ser tm.assert_series_equal(res, expected) diff --git a/pandas/tests/arithmetic/test_interval.py b/pandas/tests/arithmetic/test_interval.py index 03cc4fe2bdcb5..30a23d8563ef8 100644 --- a/pandas/tests/arithmetic/test_interval.py +++ b/pandas/tests/arithmetic/test_interval.py @@ -290,6 +290,6 @@ def test_index_series_compat(self, op, constructor, expected_type, assert_func): def test_comparison_operations(self, scalars): # GH #28981 expected = Series([False, False]) - s = pd.Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval") + s = Series([pd.Interval(0, 1), pd.Interval(1, 2)], dtype="interval") result = s == scalars tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arithmetic/test_numeric.py b/pandas/tests/arithmetic/test_numeric.py index 8b108a2f1a2b3..9716cffd626a8 100644 --- a/pandas/tests/arithmetic/test_numeric.py +++ b/pandas/tests/arithmetic/test_numeric.py @@ -42,7 +42,7 @@ def adjust_negative_zero(zero, expected): # TODO: remove this kludge once mypy stops giving false positives here # List comprehension has incompatible type List[PandasObject]; expected List[RangeIndex] # See GH#29725 -ser_or_index: List[Any] = [pd.Series, pd.Index] +ser_or_index: List[Any] = [Series, pd.Index] lefts: List[Any] = [pd.RangeIndex(10, 40, 10)] lefts.extend( [ @@ -59,14 +59,14 @@ def adjust_negative_zero(zero, expected): class TestNumericComparisons: def test_operator_series_comparison_zerorank(self): # GH#13006 - result = np.float64(0) > pd.Series([1, 2, 3]) - expected = 0.0 > pd.Series([1, 2, 3]) + result = np.float64(0) > Series([1, 2, 3]) + expected = 0.0 > Series([1, 2, 3]) tm.assert_series_equal(result, expected) - result = pd.Series([1, 2, 3]) < np.float64(0) - expected = pd.Series([1, 2, 3]) < 0.0 + result = Series([1, 2, 3]) < np.float64(0) + expected = Series([1, 2, 3]) < 0.0 tm.assert_series_equal(result, expected) - result = np.array([0, 1, 2])[0] > pd.Series([0, 1, 2]) - expected = 0.0 > pd.Series([1, 2, 3]) + result = np.array([0, 1, 2])[0] > Series([0, 1, 2]) + expected = 0.0 > Series([1, 2, 3]) tm.assert_series_equal(result, expected) def test_df_numeric_cmp_dt64_raises(self): @@ -92,8 +92,8 @@ def test_df_numeric_cmp_dt64_raises(self): def test_compare_invalid(self): # GH#8058 # ops testing - a = pd.Series(np.random.randn(5), name=0) - b = pd.Series(np.random.randn(5)) + a = Series(np.random.randn(5), name=0) + b = Series(np.random.randn(5)) b.name = pd.Timestamp("2000-01-01") tm.assert_series_equal(a / b, 1 / (b / a)) @@ -102,12 +102,12 @@ def test_numeric_cmp_string_numexpr_path(self, box_with_array): box = box_with_array xbox = box if box is not pd.Index else np.ndarray - obj = pd.Series(np.random.randn(10 ** 5)) + obj = Series(np.random.randn(10 ** 5)) obj = tm.box_expected(obj, box, transpose=False) result = obj == "a" - expected = pd.Series(np.zeros(10 ** 5, dtype=bool)) + expected = Series(np.zeros(10 ** 5, dtype=bool)) expected = tm.box_expected(expected, xbox, transpose=False) tm.assert_equal(result, expected) @@ -126,7 +126,7 @@ def test_numeric_cmp_string_numexpr_path(self, box_with_array): class TestNumericArraylikeArithmeticWithDatetimeLike: # TODO: also check name retentention - @pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series]) + @pytest.mark.parametrize("box_cls", [np.array, pd.Index, Series]) @pytest.mark.parametrize( "left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype) ) @@ -136,8 +136,8 @@ def test_mul_td64arr(self, left, box_cls): right = box_cls(right) expected = pd.TimedeltaIndex(["10s", "40s", "90s"]) - if isinstance(left, pd.Series) or box_cls is pd.Series: - expected = pd.Series(expected) + if isinstance(left, Series) or box_cls is Series: + expected = Series(expected) result = left * right tm.assert_equal(result, expected) @@ -146,7 +146,7 @@ def test_mul_td64arr(self, left, box_cls): tm.assert_equal(result, expected) # TODO: also check name retentention - @pytest.mark.parametrize("box_cls", [np.array, pd.Index, pd.Series]) + @pytest.mark.parametrize("box_cls", [np.array, pd.Index, Series]) @pytest.mark.parametrize( "left", lefts, ids=lambda x: type(x).__name__ + str(x.dtype) ) @@ -156,8 +156,8 @@ def test_div_td64arr(self, left, box_cls): right = box_cls(right) expected = pd.TimedeltaIndex(["1s", "2s", "3s"]) - if isinstance(left, pd.Series) or box_cls is pd.Series: - expected = pd.Series(expected) + if isinstance(left, Series) or box_cls is Series: + expected = Series(expected) result = right / left tm.assert_equal(result, expected) @@ -402,8 +402,8 @@ def test_ser_div_ser(self, dtype1, any_real_dtype): def test_ser_divmod_zero(self, dtype1, any_real_dtype): # GH#26987 dtype2 = any_real_dtype - left = pd.Series([1, 1]).astype(dtype1) - right = pd.Series([0, 2]).astype(dtype2) + left = Series([1, 1]).astype(dtype1) + right = Series([0, 2]).astype(dtype2) # GH#27321 pandas convention is to set 1 // 0 to np.inf, as opposed # to numpy which sets to np.nan; patch `expected[0]` below @@ -422,8 +422,8 @@ def test_ser_divmod_zero(self, dtype1, any_real_dtype): tm.assert_series_equal(result[1], expected[1]) def test_ser_divmod_inf(self): - left = pd.Series([np.inf, 1.0]) - right = pd.Series([np.inf, 2.0]) + left = Series([np.inf, 1.0]) + right = Series([np.inf, 2.0]) expected = left // right, left % right result = divmod(left, right) @@ -480,8 +480,8 @@ def test_df_div_zero_df(self): df = pd.DataFrame({"first": [3, 4, 5, 8], "second": [0, 0, 0, 3]}) result = df / df - first = pd.Series([1.0, 1.0, 1.0, 1.0]) - second = pd.Series([np.nan, np.nan, np.nan, 1]) + first = Series([1.0, 1.0, 1.0, 1.0]) + second = Series([np.nan, np.nan, np.nan, 1]) expected = pd.DataFrame({"first": first, "second": second}) tm.assert_frame_equal(result, expected) @@ -489,8 +489,8 @@ def test_df_div_zero_array(self): # integer div, but deal with the 0's (GH#9144) df = pd.DataFrame({"first": [3, 4, 5, 8], "second": [0, 0, 0, 3]}) - first = pd.Series([1.0, 1.0, 1.0, 1.0]) - second = pd.Series([np.nan, np.nan, np.nan, 1]) + first = Series([1.0, 1.0, 1.0, 1.0]) + second = Series([np.nan, np.nan, np.nan, 1]) expected = pd.DataFrame({"first": first, "second": second}) with np.errstate(all="ignore"): @@ -530,8 +530,8 @@ def test_df_mod_zero_df(self): # this is technically wrong, as the integer portion is coerced to float # ### - first = pd.Series([0, 0, 0, 0], dtype="float64") - second = pd.Series([np.nan, np.nan, np.nan, 0]) + first = Series([0, 0, 0, 0], dtype="float64") + second = Series([np.nan, np.nan, np.nan, 0]) expected = pd.DataFrame({"first": first, "second": second}) result = df % df tm.assert_frame_equal(result, expected) @@ -542,8 +542,8 @@ def test_df_mod_zero_array(self): # this is technically wrong, as the integer portion is coerced to float # ### - first = pd.Series([0, 0, 0, 0], dtype="float64") - second = pd.Series([np.nan, np.nan, np.nan, 0]) + first = Series([0, 0, 0, 0], dtype="float64") + second = Series([np.nan, np.nan, np.nan, 0]) expected = pd.DataFrame({"first": first, "second": second}) # numpy has a slightly different (wrong) treatment @@ -812,14 +812,14 @@ class TestAdditionSubtraction: "first, second, expected", [ ( - pd.Series([1, 2, 3], index=list("ABC"), name="x"), - pd.Series([2, 2, 2], index=list("ABD"), name="x"), - pd.Series([3.0, 4.0, np.nan, np.nan], index=list("ABCD"), name="x"), + Series([1, 2, 3], index=list("ABC"), name="x"), + Series([2, 2, 2], index=list("ABD"), name="x"), + Series([3.0, 4.0, np.nan, np.nan], index=list("ABCD"), name="x"), ), ( - pd.Series([1, 2, 3], index=list("ABC"), name="x"), - pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x"), - pd.Series([3, 4, 5, np.nan], index=list("ABCD"), name="x"), + Series([1, 2, 3], index=list("ABC"), name="x"), + Series([2, 2, 2, 2], index=list("ABCD"), name="x"), + Series([3, 4, 5, np.nan], index=list("ABCD"), name="x"), ), ], ) @@ -851,7 +851,7 @@ def test_add_frames(self, first, second, expected): # TODO: This came from series.test.test_operators, needs cleanup def test_series_frame_radd_bug(self): # GH#353 - vals = pd.Series(tm.rands_array(5, 10)) + vals = Series(tm.rands_array(5, 10)) result = "foo_" + vals expected = vals.map(lambda x: "foo_" + x) tm.assert_series_equal(result, expected) @@ -876,14 +876,14 @@ def test_series_frame_radd_bug(self): # TODO: This came from series.test.test_operators, needs cleanup def test_datetime64_with_index(self): # arithmetic integer ops with an index - ser = pd.Series(np.random.randn(5)) + ser = Series(np.random.randn(5)) expected = ser - ser.index.to_series() result = ser - ser.index tm.assert_series_equal(result, expected) # GH#4629 # arithmetic datetime64 ops with an index - ser = pd.Series( + ser = Series( pd.date_range("20130101", periods=5), index=pd.date_range("20130101", periods=5), ) @@ -910,7 +910,7 @@ def test_frame_operators(self, float_frame): frame2 = pd.DataFrame(float_frame, columns=["D", "C", "B", "A"]) garbage = np.random.random(4) - colSeries = pd.Series(garbage, index=np.array(frame.columns)) + colSeries = Series(garbage, index=np.array(frame.columns)) idSum = frame + frame seriesSum = frame + colSeries @@ -1033,8 +1033,8 @@ def test_series_divmod_zero(self): other = tser * 0 result = divmod(tser, other) - exp1 = pd.Series([np.inf] * len(tser), index=tser.index, name="ts") - exp2 = pd.Series([np.nan] * len(tser), index=tser.index, name="ts") + exp1 = Series([np.inf] * len(tser), index=tser.index, name="ts") + exp2 = Series([np.nan] * len(tser), index=tser.index, name="ts") tm.assert_series_equal(result[0], exp1) tm.assert_series_equal(result[1], exp2) @@ -1042,10 +1042,10 @@ def test_series_divmod_zero(self): class TestUFuncCompat: @pytest.mark.parametrize( "holder", - [pd.Int64Index, pd.UInt64Index, pd.Float64Index, pd.RangeIndex, pd.Series], + [pd.Int64Index, pd.UInt64Index, pd.Float64Index, pd.RangeIndex, Series], ) def test_ufunc_compat(self, holder): - box = pd.Series if holder is pd.Series else pd.Index + box = Series if holder is Series else pd.Index if holder is pd.RangeIndex: idx = pd.RangeIndex(0, 5) @@ -1056,11 +1056,11 @@ def test_ufunc_compat(self, holder): tm.assert_equal(result, expected) @pytest.mark.parametrize( - "holder", [pd.Int64Index, pd.UInt64Index, pd.Float64Index, pd.Series] + "holder", [pd.Int64Index, pd.UInt64Index, pd.Float64Index, Series] ) def test_ufunc_coercions(self, holder): idx = holder([1, 2, 3, 4, 5], name="x") - box = pd.Series if holder is pd.Series else pd.Index + box = Series if holder is Series else pd.Index result = np.sqrt(idx) assert result.dtype == "f8" and isinstance(result, box) @@ -1100,11 +1100,11 @@ def test_ufunc_coercions(self, holder): tm.assert_equal(result, exp) @pytest.mark.parametrize( - "holder", [pd.Int64Index, pd.UInt64Index, pd.Float64Index, pd.Series] + "holder", [pd.Int64Index, pd.UInt64Index, pd.Float64Index, Series] ) def test_ufunc_multiple_return_values(self, holder): obj = holder([1, 2, 3], name="x") - box = pd.Series if holder is pd.Series else pd.Index + box = Series if holder is Series else pd.Index result = np.modf(obj) assert isinstance(result, tuple) @@ -1114,9 +1114,9 @@ def test_ufunc_multiple_return_values(self, holder): tm.assert_equal(result[1], tm.box_expected(exp2, box)) def test_ufunc_at(self): - s = pd.Series([0, 1, 2], index=[1, 2, 3], name="x") + s = Series([0, 1, 2], index=[1, 2, 3], name="x") np.add.at(s, [0, 2], 10) - expected = pd.Series([10, 1, 12], index=[1, 2, 3], name="x") + expected = Series([10, 1, 12], index=[1, 2, 3], name="x") tm.assert_series_equal(s, expected) @@ -1126,8 +1126,8 @@ class TestObjectDtypeEquivalence: @pytest.mark.parametrize("dtype", [None, object]) def test_numarr_with_dtype_add_nan(self, dtype, box_with_array): box = box_with_array - ser = pd.Series([1, 2, 3], dtype=dtype) - expected = pd.Series([np.nan, np.nan, np.nan], dtype=dtype) + ser = Series([1, 2, 3], dtype=dtype) + expected = Series([np.nan, np.nan, np.nan], dtype=dtype) ser = tm.box_expected(ser, box) expected = tm.box_expected(expected, box) @@ -1141,8 +1141,8 @@ def test_numarr_with_dtype_add_nan(self, dtype, box_with_array): @pytest.mark.parametrize("dtype", [None, object]) def test_numarr_with_dtype_add_int(self, dtype, box_with_array): box = box_with_array - ser = pd.Series([1, 2, 3], dtype=dtype) - expected = pd.Series([2, 3, 4], dtype=dtype) + ser = Series([1, 2, 3], dtype=dtype) + expected = Series([2, 3, 4], dtype=dtype) ser = tm.box_expected(ser, box) expected = tm.box_expected(expected, box) @@ -1160,7 +1160,7 @@ def test_numarr_with_dtype_add_int(self, dtype, box_with_array): ) def test_operators_reverse_object(self, op): # GH#56 - arr = pd.Series(np.random.randn(10), index=np.arange(10), dtype=object) + arr = Series(np.random.randn(10), index=np.arange(10), dtype=object) result = op(1.0, arr) expected = op(1.0, arr.astype(float)) @@ -1224,9 +1224,9 @@ def test_arithmetic_with_frame_or_series(self, op): # check that we return NotImplemented when operating with Series # or DataFrame index = pd.RangeIndex(5) - other = pd.Series(np.random.randn(5)) + other = Series(np.random.randn(5)) - expected = op(pd.Series(index), other) + expected = op(Series(index), other) result = op(index, other) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/arithmetic/test_object.py b/pandas/tests/arithmetic/test_object.py index e0c03f28f7af5..ddd14af0918de 100644 --- a/pandas/tests/arithmetic/test_object.py +++ b/pandas/tests/arithmetic/test_object.py @@ -95,8 +95,8 @@ def test_add_extension_scalar(self, other, box_with_array, op): # Check that scalars satisfying is_extension_array_dtype(obj) # do not incorrectly try to dispatch to an ExtensionArray operation - arr = pd.Series(["a", "b", "c"]) - expected = pd.Series([op(x, other) for x in arr]) + arr = Series(["a", "b", "c"]) + expected = Series([op(x, other) for x in arr]) arr = tm.box_expected(arr, box_with_array) expected = tm.box_expected(expected, box_with_array) @@ -105,8 +105,8 @@ def test_add_extension_scalar(self, other, box_with_array, op): tm.assert_equal(result, expected) def test_objarr_add_str(self, box_with_array): - ser = pd.Series(["x", np.nan, "x"]) - expected = pd.Series(["xa", np.nan, "xa"]) + ser = Series(["x", np.nan, "x"]) + expected = Series(["xa", np.nan, "xa"]) ser = tm.box_expected(ser, box_with_array) expected = tm.box_expected(expected, box_with_array) @@ -115,8 +115,8 @@ def test_objarr_add_str(self, box_with_array): tm.assert_equal(result, expected) def test_objarr_radd_str(self, box_with_array): - ser = pd.Series(["x", np.nan, "x"]) - expected = pd.Series(["ax", np.nan, "ax"]) + ser = Series(["x", np.nan, "x"]) + expected = Series(["ax", np.nan, "ax"]) ser = tm.box_expected(ser, box_with_array) expected = tm.box_expected(expected, box_with_array) @@ -166,22 +166,22 @@ def test_objarr_add_invalid(self, op, box_with_array): def test_operators_na_handling(self): ser = Series(["foo", "bar", "baz", np.nan]) result = "prefix_" + ser - expected = pd.Series(["prefix_foo", "prefix_bar", "prefix_baz", np.nan]) + expected = Series(["prefix_foo", "prefix_bar", "prefix_baz", np.nan]) tm.assert_series_equal(result, expected) result = ser + "_suffix" - expected = pd.Series(["foo_suffix", "bar_suffix", "baz_suffix", np.nan]) + expected = Series(["foo_suffix", "bar_suffix", "baz_suffix", np.nan]) tm.assert_series_equal(result, expected) # TODO: parametrize over box @pytest.mark.parametrize("dtype", [None, object]) def test_series_with_dtype_radd_timedelta(self, dtype): # note this test is _not_ aimed at timedelta64-dtyped Series - ser = pd.Series( + ser = Series( [pd.Timedelta("1 days"), pd.Timedelta("2 days"), pd.Timedelta("3 days")], dtype=dtype, ) - expected = pd.Series( + expected = Series( [pd.Timedelta("4 days"), pd.Timedelta("5 days"), pd.Timedelta("6 days")] ) @@ -194,7 +194,7 @@ def test_series_with_dtype_radd_timedelta(self, dtype): # TODO: cleanup & parametrize over box def test_mixed_timezone_series_ops_object(self): # GH#13043 - ser = pd.Series( + ser = Series( [ pd.Timestamp("2015-01-01", tz="US/Eastern"), pd.Timestamp("2015-01-01", tz="Asia/Tokyo"), @@ -203,7 +203,7 @@ def test_mixed_timezone_series_ops_object(self): ) assert ser.dtype == object - exp = pd.Series( + exp = Series( [ pd.Timestamp("2015-01-02", tz="US/Eastern"), pd.Timestamp("2015-01-02", tz="Asia/Tokyo"), @@ -214,7 +214,7 @@ def test_mixed_timezone_series_ops_object(self): tm.assert_series_equal(pd.Timedelta("1 days") + ser, exp) # object series & object series - ser2 = pd.Series( + ser2 = Series( [ pd.Timestamp("2015-01-03", tz="US/Eastern"), pd.Timestamp("2015-01-05", tz="Asia/Tokyo"), @@ -222,27 +222,25 @@ def test_mixed_timezone_series_ops_object(self): name="xxx", ) assert ser2.dtype == object - exp = pd.Series([pd.Timedelta("2 days"), pd.Timedelta("4 days")], name="xxx") + exp = Series([pd.Timedelta("2 days"), pd.Timedelta("4 days")], name="xxx") tm.assert_series_equal(ser2 - ser, exp) tm.assert_series_equal(ser - ser2, -exp) - ser = pd.Series( + ser = Series( [pd.Timedelta("01:00:00"), pd.Timedelta("02:00:00")], name="xxx", dtype=object, ) assert ser.dtype == object - exp = pd.Series( - [pd.Timedelta("01:30:00"), pd.Timedelta("02:30:00")], name="xxx" - ) + exp = Series([pd.Timedelta("01:30:00"), pd.Timedelta("02:30:00")], name="xxx") tm.assert_series_equal(ser + pd.Timedelta("00:30:00"), exp) tm.assert_series_equal(pd.Timedelta("00:30:00") + ser, exp) # TODO: cleanup & parametrize over box def test_iadd_preserves_name(self): # GH#17067, GH#19723 __iadd__ and __isub__ should preserve index name - ser = pd.Series([1, 2, 3]) + ser = Series([1, 2, 3]) ser.index.name = "foo" ser.index += 1 diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index e78e696d00398..f02259a1c7e62 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -449,10 +449,10 @@ def _check(self, values, func, expected): assert isinstance(expected, (pd.Index, np.ndarray)) tm.assert_equal(result, expected) - s = pd.Series(values) + s = Series(values) result = func(s) - exp = pd.Series(expected, name=values.name) + exp = Series(expected, name=values.name) tm.assert_series_equal(result, exp) def test_pi_comp_period(self): @@ -1247,13 +1247,13 @@ def test_parr_add_sub_object_array(self): class TestPeriodSeriesArithmetic: def test_ops_series_timedelta(self): # GH#13043 - ser = pd.Series( + ser = Series( [pd.Period("2015-01-01", freq="D"), pd.Period("2015-01-02", freq="D")], name="xxx", ) assert ser.dtype == "Period[D]" - expected = pd.Series( + expected = Series( [pd.Period("2015-01-02", freq="D"), pd.Period("2015-01-03", freq="D")], name="xxx", ) @@ -1272,7 +1272,7 @@ def test_ops_series_timedelta(self): def test_ops_series_period(self): # GH#13043 - ser = pd.Series( + ser = Series( [pd.Period("2015-01-01", freq="D"), pd.Period("2015-01-02", freq="D")], name="xxx", ) @@ -1281,17 +1281,17 @@ def test_ops_series_period(self): per = pd.Period("2015-01-10", freq="D") off = per.freq # dtype will be object because of original dtype - expected = pd.Series([9 * off, 8 * off], name="xxx", dtype=object) + expected = Series([9 * off, 8 * off], name="xxx", dtype=object) tm.assert_series_equal(per - ser, expected) tm.assert_series_equal(ser - per, -1 * expected) - s2 = pd.Series( + s2 = Series( [pd.Period("2015-01-05", freq="D"), pd.Period("2015-01-04", freq="D")], name="xxx", ) assert s2.dtype == "Period[D]" - expected = pd.Series([4 * off, 2 * off], name="xxx", dtype=object) + expected = Series([4 * off, 2 * off], name="xxx", dtype=object) tm.assert_series_equal(s2 - ser, expected) tm.assert_series_equal(ser - s2, -1 * expected) @@ -1304,10 +1304,10 @@ def _check(self, values, func, expected): result = func(idx) tm.assert_equal(result, expected) - ser = pd.Series(values) + ser = Series(values) result = func(ser) - exp = pd.Series(expected, name=values.name) + exp = Series(expected, name=values.name) tm.assert_series_equal(result, exp) def test_pi_ops(self): @@ -1455,7 +1455,7 @@ def test_pi_offset_errors(self): freq="D", name="idx", ) - ser = pd.Series(idx) + ser = Series(idx) # Series op is applied per Period instance, thus error is raised # from Period diff --git a/pandas/tests/arithmetic/test_timedelta64.py b/pandas/tests/arithmetic/test_timedelta64.py index 90a3ed6d75393..cd6a430829442 100644 --- a/pandas/tests/arithmetic/test_timedelta64.py +++ b/pandas/tests/arithmetic/test_timedelta64.py @@ -77,10 +77,10 @@ def test_compare_timedeltalike_scalar(self, box_with_array, td_scalar): box = box_with_array xbox = box if box not in [pd.Index, pd.array] else np.ndarray - ser = pd.Series([timedelta(days=1), timedelta(days=2)]) + ser = Series([timedelta(days=1), timedelta(days=2)]) ser = tm.box_expected(ser, box) actual = ser > td_scalar - expected = pd.Series([False, True]) + expected = Series([False, True]) expected = tm.box_expected(expected, xbox) tm.assert_equal(actual, expected) @@ -1104,7 +1104,7 @@ def test_td64arr_sub_periodlike(self, box_with_array, tdi_freq, pi_freq): ) def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other): # vector-like others are tested in test_td64arr_add_sub_numeric_arr_invalid - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") tdarr = tm.box_expected(tdser, box_with_array) assert_invalid_addsub_type(tdarr, other) @@ -1122,7 +1122,7 @@ def test_td64arr_addsub_numeric_scalar_invalid(self, box_with_array, other): def test_td64arr_addsub_numeric_arr_invalid( self, box_with_array, vec, any_real_dtype ): - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") tdarr = tm.box_expected(tdser, box_with_array) vector = vec.astype(any_real_dtype) @@ -1556,7 +1556,7 @@ def test_tdi_mul_int_series(self, box_with_array): idx = tm.box_expected(idx, box) expected = tm.box_expected(expected, xbox) - result = idx * pd.Series(np.arange(5, dtype="int64")) + result = idx * Series(np.arange(5, dtype="int64")) tm.assert_equal(result, expected) def test_tdi_mul_float_series(self, box_with_array): @@ -1765,8 +1765,8 @@ def test_td64arr_floordiv_td64arr_with_nat(self, box_with_array): box = box_with_array xbox = np.ndarray if box is pd.array else box - left = pd.Series([1000, 222330, 30], dtype="timedelta64[ns]") - right = pd.Series([1000, 222330, None], dtype="timedelta64[ns]") + left = Series([1000, 222330, 30], dtype="timedelta64[ns]") + right = Series([1000, 222330, None], dtype="timedelta64[ns]") left = tm.box_expected(left, box) right = tm.box_expected(right, box) @@ -1988,7 +1988,7 @@ def test_td64arr_mul_td64arr_raises(self, box_with_array): def test_td64arr_mul_numeric_scalar(self, box_with_array, one): # GH#4521 # divide/multiply by integers - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") expected = Series(["-59 Days", "-59 Days", "NaT"], dtype="timedelta64[ns]") tdser = tm.box_expected(tdser, box_with_array) @@ -2011,7 +2011,7 @@ def test_td64arr_mul_numeric_scalar(self, box_with_array, one): def test_td64arr_div_numeric_scalar(self, box_with_array, two): # GH#4521 # divide/multiply by integers - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") expected = Series(["29.5D", "29.5D", "NaT"], dtype="timedelta64[ns]") tdser = tm.box_expected(tdser, box_with_array) @@ -2033,7 +2033,7 @@ def test_td64arr_rmul_numeric_array(self, box_with_array, vector, any_real_dtype # divide/multiply by integers xbox = get_upcast_box(box_with_array, vector) - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") vector = vector.astype(any_real_dtype) expected = Series(["1180 Days", "1770 Days", "NaT"], dtype="timedelta64[ns]") @@ -2057,7 +2057,7 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype) # divide/multiply by integers xbox = get_upcast_box(box_with_array, vector) - tdser = pd.Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") + tdser = Series(["59 Days", "59 Days", "NaT"], dtype="m8[ns]") vector = vector.astype(any_real_dtype) expected = Series(["2.95D", "1D 23H 12m", "NaT"], dtype="timedelta64[ns]") diff --git a/pandas/tests/arrays/categorical/test_indexing.py b/pandas/tests/arrays/categorical/test_indexing.py index 2c4dd8fe64057..91992da594288 100644 --- a/pandas/tests/arrays/categorical/test_indexing.py +++ b/pandas/tests/arrays/categorical/test_indexing.py @@ -200,40 +200,38 @@ def test_get_indexer_non_unique(self, idx_values, key_values, key_class): tm.assert_numpy_array_equal(exp_miss, res_miss) def test_where_unobserved_nan(self): - ser = pd.Series(pd.Categorical(["a", "b"])) + ser = Series(pd.Categorical(["a", "b"])) result = ser.where([True, False]) - expected = pd.Series(pd.Categorical(["a", None], categories=["a", "b"])) + expected = Series(pd.Categorical(["a", None], categories=["a", "b"])) tm.assert_series_equal(result, expected) # all NA - ser = pd.Series(pd.Categorical(["a", "b"])) + ser = Series(pd.Categorical(["a", "b"])) result = ser.where([False, False]) - expected = pd.Series(pd.Categorical([None, None], categories=["a", "b"])) + expected = Series(pd.Categorical([None, None], categories=["a", "b"])) tm.assert_series_equal(result, expected) def test_where_unobserved_categories(self): - ser = pd.Series(Categorical(["a", "b", "c"], categories=["d", "c", "b", "a"])) + ser = Series(Categorical(["a", "b", "c"], categories=["d", "c", "b", "a"])) result = ser.where([True, True, False], other="b") - expected = pd.Series( - Categorical(["a", "b", "b"], categories=ser.cat.categories) - ) + expected = Series(Categorical(["a", "b", "b"], categories=ser.cat.categories)) tm.assert_series_equal(result, expected) def test_where_other_categorical(self): - ser = pd.Series(Categorical(["a", "b", "c"], categories=["d", "c", "b", "a"])) + ser = Series(Categorical(["a", "b", "c"], categories=["d", "c", "b", "a"])) other = Categorical(["b", "c", "a"], categories=["a", "c", "b", "d"]) result = ser.where([True, False, True], other) - expected = pd.Series(Categorical(["a", "c", "c"], dtype=ser.dtype)) + expected = Series(Categorical(["a", "c", "c"], dtype=ser.dtype)) tm.assert_series_equal(result, expected) def test_where_new_category_raises(self): - ser = pd.Series(Categorical(["a", "b", "c"])) + ser = Series(Categorical(["a", "b", "c"])) msg = "Cannot setitem on a Categorical with a new category" with pytest.raises(ValueError, match=msg): ser.where([True, False, True], "d") def test_where_ordered_differs_rasies(self): - ser = pd.Series( + ser = Series( Categorical(["a", "b", "c"], categories=["d", "c", "b", "a"], ordered=True) ) other = Categorical( diff --git a/pandas/tests/base/test_conversion.py b/pandas/tests/base/test_conversion.py index 26ad6fc1c6572..7867d882befa0 100644 --- a/pandas/tests/base/test_conversion.py +++ b/pandas/tests/base/test_conversion.py @@ -208,7 +208,7 @@ def test_iter_box(self): ], ) def test_values_consistent(array, expected_type, dtype): - l_values = pd.Series(array)._values + l_values = Series(array)._values r_values = pd.Index(array)._values assert type(l_values) is expected_type assert type(l_values) is type(r_values) @@ -218,14 +218,14 @@ def test_values_consistent(array, expected_type, dtype): @pytest.mark.parametrize("arr", [np.array([1, 2, 3])]) def test_numpy_array(arr): - ser = pd.Series(arr) + ser = Series(arr) result = ser.array expected = PandasArray(arr) tm.assert_extension_array_equal(result, expected) def test_numpy_array_all_dtypes(any_numpy_dtype): - ser = pd.Series(dtype=any_numpy_dtype) + ser = Series(dtype=any_numpy_dtype) result = ser.array if is_datetime64_dtype(any_numpy_dtype): assert isinstance(result, DatetimeArray) @@ -336,7 +336,7 @@ def test_to_numpy(array, expected, index_or_series): def test_to_numpy_copy(arr, as_series): obj = pd.Index(arr, copy=False) if as_series: - obj = pd.Series(obj.values, copy=False) + obj = Series(obj.values, copy=False) # no copy by default result = obj.to_numpy() @@ -355,7 +355,7 @@ def test_to_numpy_dtype(as_series): tz = "US/Eastern" obj = pd.DatetimeIndex(["2000", "2001"], tz=tz) if as_series: - obj = pd.Series(obj) + obj = Series(obj) # preserve tz by default result = obj.to_numpy() @@ -395,13 +395,13 @@ def test_to_numpy_na_value_numpy_dtype( def test_to_numpy_kwargs_raises(): # numpy - s = pd.Series([1, 2, 3]) + s = Series([1, 2, 3]) msg = r"to_numpy\(\) got an unexpected keyword argument 'foo'" with pytest.raises(TypeError, match=msg): s.to_numpy(foo=True) # extension - s = pd.Series([1, 2, 3], dtype="Int64") + s = Series([1, 2, 3], dtype="Int64") with pytest.raises(TypeError, match=msg): s.to_numpy(foo=True) diff --git a/pandas/tests/base/test_misc.py b/pandas/tests/base/test_misc.py index 2dc2fe6d2ad07..96aec2e27939a 100644 --- a/pandas/tests/base/test_misc.py +++ b/pandas/tests/base/test_misc.py @@ -182,7 +182,7 @@ def test_access_by_position(index): elif isinstance(index, pd.MultiIndex): pytest.skip("Can't instantiate Series from MultiIndex") - series = pd.Series(index) + series = Series(index) assert index[0] == series.iloc[0] assert index[5] == series.iloc[5] assert index[-1] == series.iloc[-1] diff --git a/pandas/tests/base/test_value_counts.py b/pandas/tests/base/test_value_counts.py index 73a41e7010c5f..602133bb4122e 100644 --- a/pandas/tests/base/test_value_counts.py +++ b/pandas/tests/base/test_value_counts.py @@ -30,7 +30,7 @@ def test_value_counts(index_or_series_obj): result = obj.value_counts() counter = collections.Counter(obj) - expected = pd.Series(dict(counter.most_common()), dtype=np.int64, name=obj.name) + expected = Series(dict(counter.most_common()), dtype=np.int64, name=obj.name) expected.index = expected.index.astype(obj.dtype) if isinstance(obj, pd.MultiIndex): expected.index = pd.Index(expected.index) @@ -67,7 +67,7 @@ def test_value_counts_null(null_obj, index_or_series_obj): # because np.nan == np.nan is False, but None == None is True # np.nan would be duplicated, whereas None wouldn't counter = collections.Counter(obj.dropna()) - expected = pd.Series(dict(counter.most_common()), dtype=np.int64) + expected = Series(dict(counter.most_common()), dtype=np.int64) expected.index = expected.index.astype(obj.dtype) result = obj.value_counts() @@ -80,7 +80,7 @@ def test_value_counts_null(null_obj, index_or_series_obj): # can't use expected[null_obj] = 3 as # IntervalIndex doesn't allow assignment - new_entry = pd.Series({np.nan: 3}, dtype=np.int64) + new_entry = Series({np.nan: 3}, dtype=np.int64) expected = expected.append(new_entry) result = obj.value_counts(dropna=False) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index f6cd500f911b2..a419cb0dded79 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -953,9 +953,9 @@ def test_registry_find(dtype, expected): (bool, True), (np.bool_, True), (np.array(["a", "b"]), False), - (pd.Series([1, 2]), False), + (Series([1, 2]), False), (np.array([True, False]), True), - (pd.Series([True, False]), True), + (Series([True, False]), True), (SparseArray([True, False]), True), (SparseDtype(bool), True), ], @@ -966,7 +966,7 @@ def test_is_bool_dtype(dtype, expected): def test_is_bool_dtype_sparse(): - result = is_bool_dtype(pd.Series(SparseArray([True, False]))) + result = is_bool_dtype(Series(SparseArray([True, False]))) assert result is True diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 7fa83eeac8400..d9b229d61248d 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1223,7 +1223,7 @@ def test_interval(self): inferred = lib.infer_dtype(idx._data, skipna=False) assert inferred == "interval" - inferred = lib.infer_dtype(pd.Series(idx), skipna=False) + inferred = lib.infer_dtype(Series(idx), skipna=False) assert inferred == "interval" @pytest.mark.parametrize("klass", [pd.array, pd.Series]) diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 046b82ef3131a..e7b5d2598d8e7 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -90,8 +90,8 @@ def test_isna_isnull(self, isna_f): assert not isna_f(-np.inf) # type - assert not isna_f(type(pd.Series(dtype=object))) - assert not isna_f(type(pd.Series(dtype=np.float64))) + assert not isna_f(type(Series(dtype=object))) + assert not isna_f(type(Series(dtype=np.float64))) assert not isna_f(type(pd.DataFrame())) # series @@ -247,11 +247,11 @@ def test_datetime_other_units(self): tm.assert_numpy_array_equal(isna(values), exp) tm.assert_numpy_array_equal(notna(values), ~exp) - exp = pd.Series([False, True, False]) - s = pd.Series(values) + exp = Series([False, True, False]) + s = Series(values) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) - s = pd.Series(values, dtype=object) + s = Series(values, dtype=object) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) @@ -278,11 +278,11 @@ def test_timedelta_other_units(self): tm.assert_numpy_array_equal(isna(values), exp) tm.assert_numpy_array_equal(notna(values), ~exp) - exp = pd.Series([False, True, False]) - s = pd.Series(values) + exp = Series([False, True, False]) + s = Series(values) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) - s = pd.Series(values, dtype=object) + s = Series(values, dtype=object) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) @@ -292,11 +292,11 @@ def test_period(self): tm.assert_numpy_array_equal(isna(idx), exp) tm.assert_numpy_array_equal(notna(idx), ~exp) - exp = pd.Series([False, True, False]) - s = pd.Series(idx) + exp = Series([False, True, False]) + s = Series(idx) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) - s = pd.Series(idx, dtype=object) + s = Series(idx, dtype=object) tm.assert_series_equal(isna(s), exp) tm.assert_series_equal(notna(s), ~exp) diff --git a/pandas/tests/frame/apply/test_frame_apply.py b/pandas/tests/frame/apply/test_frame_apply.py index 598da9c52731e..58e91c38fc294 100644 --- a/pandas/tests/frame/apply/test_frame_apply.py +++ b/pandas/tests/frame/apply/test_frame_apply.py @@ -359,7 +359,7 @@ def test_apply_reduce_Series(self, float_frame): def test_apply_reduce_rows_to_dict(self): # GH 25196 data = pd.DataFrame([[1, 2], [3, 4]]) - expected = pd.Series([{0: 1, 1: 3}, {0: 2, 1: 4}]) + expected = Series([{0: 1, 1: 3}, {0: 2, 1: 4}]) result = data.apply(dict) tm.assert_series_equal(result, expected) @@ -647,7 +647,7 @@ def test_applymap_na_ignore(self, float_frame): def test_applymap_box_timestamps(self): # GH 2689, GH 2627 - ser = pd.Series(date_range("1/1/2000", periods=10)) + ser = Series(date_range("1/1/2000", periods=10)) def func(x): return (x.hour, x.day, x.month) @@ -815,7 +815,7 @@ def test_apply_category_equalness(self, val): df = pd.DataFrame({"a": df_values}, dtype="category") result = df.a.apply(lambda x: x == val) - expected = pd.Series( + expected = Series( [np.NaN if pd.isnull(x) else x == val for x in df_values], name="a" ) tm.assert_series_equal(result, expected) @@ -1153,12 +1153,12 @@ def test_agg_with_name_as_column_name(self): # result's name should be None result = df.agg({"name": "count"}) - expected = pd.Series({"name": 2}) + expected = Series({"name": 2}) tm.assert_series_equal(result, expected) # Check if name is still preserved when aggregating series instead result = df["name"].agg({"name": "count"}) - expected = pd.Series({"name": 2}, name="name") + expected = Series({"name": 2}, name="name") tm.assert_series_equal(result, expected) def test_agg_multiple_mixed_no_warning(self): @@ -1376,7 +1376,7 @@ def func(group_col): return list(group_col.dropna().unique()) result = df.agg(func) - expected = pd.Series([[2, 3], [1.5], ["foo", "bar"]], index=["A", "B", "C"]) + expected = Series([[2, 3], [1.5], ["foo", "bar"]], index=["A", "B", "C"]) tm.assert_series_equal(result, expected) result = df.agg([func]) @@ -1483,9 +1483,9 @@ def f(x, a, b, c=3): df = pd.DataFrame([[1, 2], [3, 4]]) if axis == 0: - expected = pd.Series([5.0, 7.0]) + expected = Series([5.0, 7.0]) else: - expected = pd.Series([4.0, 8.0]) + expected = Series([4.0, 8.0]) result = df.agg(f, axis, *args, **kwargs) @@ -1510,7 +1510,7 @@ def test_apply_datetime_tz_issue(self): ] df = DataFrame(data=[0, 1, 2], index=timestamps) result = df.apply(lambda x: x.name, axis=1) - expected = pd.Series(index=timestamps, data=timestamps) + expected = Series(index=timestamps, data=timestamps) tm.assert_series_equal(result, expected) @@ -1559,7 +1559,7 @@ def test_apply_empty_list_reduce(): df = pd.DataFrame([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]], columns=["a", "b"]) result = df.apply(lambda x: [], result_type="reduce") - expected = pd.Series({"a": [], "b": []}, dtype=object) + expected = Series({"a": [], "b": []}, dtype=object) tm.assert_series_equal(result, expected) @@ -1578,5 +1578,5 @@ def test_apply_raw_returns_string(): # https://github.com/pandas-dev/pandas/issues/35940 df = pd.DataFrame({"A": ["aa", "bbb"]}) result = df.apply(lambda x: x[0], axis=1, raw=True) - expected = pd.Series(["aa", "bbb"]) + expected = Series(["aa", "bbb"]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index c097557b33f4e..4687d94b52c80 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -1374,7 +1374,7 @@ def test_lookup_bool(self): [df.loc[r, c] for r, c in zip(df.index, "mask_" + df["label"])] ) - tm.assert_series_equal(df["mask"], pd.Series(exp_mask, name="mask")) + tm.assert_series_equal(df["mask"], Series(exp_mask, name="mask")) assert df["mask"].dtype == np.bool_ def test_lookup_raises(self, float_frame): @@ -1922,9 +1922,7 @@ def test_setitem_with_unaligned_tz_aware_datetime_column(self): # GH 12981 # Assignment of unaligned offset-aware datetime series. # Make sure timezone isn't lost - column = pd.Series( - pd.date_range("2015-01-01", periods=3, tz="utc"), name="dates" - ) + column = Series(pd.date_range("2015-01-01", periods=3, tz="utc"), name="dates") df = pd.DataFrame({"dates": column}) df["dates"] = column[[1, 0, 2]] tm.assert_series_equal(df["dates"], column) @@ -2156,7 +2154,7 @@ def test_interval_index(self): ) index_exp = pd.interval_range(start=0, periods=2, freq=1, closed="both") - expected = pd.Series([1, 4], index=index_exp, name="A") + expected = Series([1, 4], index=index_exp, name="A") result = df.loc[1, "A"] tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/indexing/test_xs.py b/pandas/tests/frame/indexing/test_xs.py index 71b40585f0c2f..0fd2471a14fc9 100644 --- a/pandas/tests/frame/indexing/test_xs.py +++ b/pandas/tests/frame/indexing/test_xs.py @@ -53,7 +53,7 @@ def test_xs_corner(self): df["E"] = 3.0 xs = df.xs(0) - exp = pd.Series([1.0, "foo", 2.0, "bar", 3.0], index=list("ABCDE"), name=0) + exp = Series([1.0, "foo", 2.0, "bar", 3.0], index=list("ABCDE"), name=0) tm.assert_series_equal(xs, exp) # no columns but Index(dtype=object) diff --git a/pandas/tests/frame/methods/test_align.py b/pandas/tests/frame/methods/test_align.py index d19b59debfdea..9a3435885b80a 100644 --- a/pandas/tests/frame/methods/test_align.py +++ b/pandas/tests/frame/methods/test_align.py @@ -199,7 +199,7 @@ def test_align_multiindex(self): def test_align_series_combinations(self): df = pd.DataFrame({"a": [1, 3, 5], "b": [1, 3, 5]}, index=list("ACE")) - s = pd.Series([1, 2, 4], index=list("ABD"), name="x") + s = Series([1, 2, 4], index=list("ABD"), name="x") # frame + series res1, res2 = df.align(s, axis=0) @@ -207,7 +207,7 @@ def test_align_series_combinations(self): {"a": [1, np.nan, 3, np.nan, 5], "b": [1, np.nan, 3, np.nan, 5]}, index=list("ABCDE"), ) - exp2 = pd.Series([1, 2, np.nan, 4, np.nan], index=list("ABCDE"), name="x") + exp2 = Series([1, 2, np.nan, 4, np.nan], index=list("ABCDE"), name="x") tm.assert_frame_equal(res1, exp1) tm.assert_series_equal(res2, exp2) diff --git a/pandas/tests/frame/methods/test_append.py b/pandas/tests/frame/methods/test_append.py index 9fc3629e794e2..e4c469dd888b4 100644 --- a/pandas/tests/frame/methods/test_append.py +++ b/pandas/tests/frame/methods/test_append.py @@ -179,7 +179,7 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp): tz = tz_naive_fixture df = pd.DataFrame([pd.Timestamp(timestamp, tz=tz)]) result = df.append(df.iloc[0]).iloc[-1] - expected = pd.Series(pd.Timestamp(timestamp, tz=tz), name=0) + expected = Series(pd.Timestamp(timestamp, tz=tz), name=0) tm.assert_series_equal(result, expected) @pytest.mark.parametrize( @@ -195,5 +195,5 @@ def test_append_timestamps_aware_or_naive(self, tz_naive_fixture, timestamp): def test_other_dtypes(self, data, dtype): df = pd.DataFrame(data, dtype=dtype) result = df.append(df.iloc[0]).iloc[-1] - expected = pd.Series(data, name=0, dtype=dtype) + expected = Series(data, name=0, dtype=dtype) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_cov_corr.py b/pandas/tests/frame/methods/test_cov_corr.py index f307acd8c2178..87c9dc32650c0 100644 --- a/pandas/tests/frame/methods/test_cov_corr.py +++ b/pandas/tests/frame/methods/test_cov_corr.py @@ -278,10 +278,10 @@ def test_corrwith_mixed_dtypes(self): df = pd.DataFrame( {"a": [1, 4, 3, 2], "b": [4, 6, 7, 3], "c": ["a", "b", "c", "d"]} ) - s = pd.Series([0, 6, 7, 3]) + s = Series([0, 6, 7, 3]) result = df.corrwith(s) corrs = [df["a"].corr(s), df["b"].corr(s)] - expected = pd.Series(data=corrs, index=["a", "b"]) + expected = Series(data=corrs, index=["a", "b"]) tm.assert_series_equal(result, expected) def test_corrwith_index_intersection(self): @@ -307,7 +307,7 @@ def test_corrwith_dup_cols(self): df2 = pd.concat((df2, df2[0]), axis=1) result = df1.corrwith(df2) - expected = pd.Series(np.ones(4), index=[0, 0, 1, 2]) + expected = Series(np.ones(4), index=[0, 0, 1, 2]) tm.assert_series_equal(result, expected) @td.skip_if_no_scipy diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 0b70bead375da..d10d4c8ea05ab 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -300,7 +300,7 @@ def test_describe_tz_values2(self): df = pd.DataFrame({"s1": s1, "s2": s2}) s1_ = s1.describe() - s2_ = pd.Series( + s2_ = Series( [ 5, 5, diff --git a/pandas/tests/frame/methods/test_diff.py b/pandas/tests/frame/methods/test_diff.py index e160d5d24d40a..9ef6ba5f410a9 100644 --- a/pandas/tests/frame/methods/test_diff.py +++ b/pandas/tests/frame/methods/test_diff.py @@ -33,10 +33,10 @@ def test_diff(self, datetime_frame): tm.assert_series_equal(the_diff["A"], tf["A"] - tf["A"].shift(1)) # GH#10907 - df = pd.DataFrame({"y": pd.Series([2]), "z": pd.Series([3])}) + df = pd.DataFrame({"y": Series([2]), "z": Series([3])}) df.insert(0, "x", 1) result = df.diff(axis=1) - expected = pd.DataFrame({"x": np.nan, "y": pd.Series(1), "z": pd.Series(1)}) + expected = pd.DataFrame({"x": np.nan, "y": Series(1), "z": Series(1)}) tm.assert_frame_equal(result, expected) def test_diff_timedelta64_with_nat(self): @@ -65,20 +65,20 @@ def test_diff_timedelta64_with_nat(self): def test_diff_datetime_axis0_with_nat(self, tz): # GH#32441 dti = pd.DatetimeIndex(["NaT", "2019-01-01", "2019-01-02"], tz=tz) - ser = pd.Series(dti) + ser = Series(dti) df = ser.to_frame() result = df.diff() ex_index = pd.TimedeltaIndex([pd.NaT, pd.NaT, pd.Timedelta(days=1)]) - expected = pd.Series(ex_index).to_frame() + expected = Series(ex_index).to_frame() tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("tz", [None, "UTC"]) def test_diff_datetime_with_nat_zero_periods(self, tz): # diff on NaT values should give NaT, not timedelta64(0) dti = pd.date_range("2016-01-01", periods=4, tz=tz) - ser = pd.Series(dti) + ser = Series(dti) df = ser.to_frame() df[1] = ser.copy() diff --git a/pandas/tests/frame/methods/test_isin.py b/pandas/tests/frame/methods/test_isin.py index 29a3a0106c56c..fb3fbacaf2627 100644 --- a/pandas/tests/frame/methods/test_isin.py +++ b/pandas/tests/frame/methods/test_isin.py @@ -127,7 +127,7 @@ def test_isin_against_series(self): df = pd.DataFrame( {"A": [1, 2, 3, 4], "B": [2, np.nan, 4, 4]}, index=["a", "b", "c", "d"] ) - s = pd.Series([1, 3, 11, 4], index=["a", "b", "c", "d"]) + s = Series([1, 3, 11, 4], index=["a", "b", "c", "d"]) expected = DataFrame(False, index=df.index, columns=df.columns) expected["A"].loc["a"] = True expected.loc["d"] = True @@ -194,7 +194,7 @@ def test_isin_empty_datetimelike(self): "values", [ pd.DataFrame({"a": [1, 2, 3]}, dtype="category"), - pd.Series([1, 2, 3], dtype="category"), + Series([1, 2, 3], dtype="category"), ], ) def test_isin_category_frame(self, values): diff --git a/pandas/tests/frame/methods/test_quantile.py b/pandas/tests/frame/methods/test_quantile.py index 0b8f1e0495155..80e57b9d71a85 100644 --- a/pandas/tests/frame/methods/test_quantile.py +++ b/pandas/tests/frame/methods/test_quantile.py @@ -13,15 +13,15 @@ class TestDataFrameQuantile: [ pd.DataFrame( { - 0: pd.Series(pd.arrays.SparseArray([1, 2])), - 1: pd.Series(pd.arrays.SparseArray([3, 4])), + 0: Series(pd.arrays.SparseArray([1, 2])), + 1: Series(pd.arrays.SparseArray([3, 4])), } ), - pd.Series([1.5, 3.5], name=0.5), + Series([1.5, 3.5], name=0.5), ], [ - pd.DataFrame(pd.Series([0.0, None, 1.0, 2.0], dtype="Sparse[float]")), - pd.Series([1.0], name=0.5), + pd.DataFrame(Series([0.0, None, 1.0, 2.0], dtype="Sparse[float]")), + Series([1.0], name=0.5), ], ], ) @@ -78,11 +78,11 @@ def test_quantile_date_range(self): # GH 2460 dti = pd.date_range("2016-01-01", periods=3, tz="US/Pacific") - ser = pd.Series(dti) + ser = Series(dti) df = pd.DataFrame(ser) result = df.quantile(numeric_only=False) - expected = pd.Series( + expected = Series( ["2016-01-02 00:00:00"], name=0.5, dtype="datetime64[ns, US/Pacific]" ) @@ -307,7 +307,7 @@ def test_quantile_box(self): res = df.quantile(0.5, numeric_only=False) - exp = pd.Series( + exp = Series( [ pd.Timestamp("2011-01-02"), pd.Timestamp("2011-01-02", tz="US/Eastern"), @@ -376,7 +376,7 @@ def test_quantile_box(self): ) res = df.quantile(0.5, numeric_only=False) - exp = pd.Series( + exp = Series( [ pd.Timestamp("2011-01-02"), pd.Timestamp("2011-01-02"), @@ -509,7 +509,7 @@ def test_quantile_empty_no_columns(self): df = pd.DataFrame(pd.date_range("1/1/18", periods=5)) df.columns.name = "captain tightpants" result = df.quantile(0.5) - expected = pd.Series([], index=[], name=0.5, dtype=np.float64) + expected = Series([], index=[], name=0.5, dtype=np.float64) expected.index.name = "captain tightpants" tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/methods/test_replace.py b/pandas/tests/frame/methods/test_replace.py index a9cf840470ae0..569677f1fec5e 100644 --- a/pandas/tests/frame/methods/test_replace.py +++ b/pandas/tests/frame/methods/test_replace.py @@ -711,7 +711,7 @@ def test_replace_list(self): def test_replace_with_empty_list(self): # GH 21977 - s = pd.Series([["a", "b"], [], np.nan, [1]]) + s = Series([["a", "b"], [], np.nan, [1]]) df = pd.DataFrame({"col": s}) expected = df result = df.replace([], np.nan) diff --git a/pandas/tests/frame/methods/test_round.py b/pandas/tests/frame/methods/test_round.py index 3051f27882fb8..db97a3e2a0e4f 100644 --- a/pandas/tests/frame/methods/test_round.py +++ b/pandas/tests/frame/methods/test_round.py @@ -178,7 +178,7 @@ def test_round_with_duplicate_columns(self): rounded = dfs.round() tm.assert_index_equal(rounded.index, dfs.index) - decimals = pd.Series([1, 0, 2], index=["A", "B", "A"]) + decimals = Series([1, 0, 2], index=["A", "B", "A"]) msg = "Index of decimals must be unique" with pytest.raises(ValueError, match=msg): df.round(decimals) diff --git a/pandas/tests/frame/methods/test_shift.py b/pandas/tests/frame/methods/test_shift.py index 8f6902eca816f..5daecd6a475aa 100644 --- a/pandas/tests/frame/methods/test_shift.py +++ b/pandas/tests/frame/methods/test_shift.py @@ -92,8 +92,8 @@ def test_shift_bool(self): def test_shift_categorical(self): # GH#9416 - s1 = pd.Series(["a", "b", "c"], dtype="category") - s2 = pd.Series(["A", "B", "C"], dtype="category") + s1 = Series(["a", "b", "c"], dtype="category") + s2 = Series(["A", "B", "C"], dtype="category") df = DataFrame({"one": s1, "two": s2}) rs = df.shift(1) xp = DataFrame({"one": s1.shift(1), "two": s2.shift(1)}) @@ -274,13 +274,13 @@ def test_datetime_frame_shift_with_freq_error(self, datetime_frame): def test_shift_dt64values_int_fill_deprecated(self): # GH#31971 - ser = pd.Series([pd.Timestamp("2020-01-01"), pd.Timestamp("2020-01-02")]) + ser = Series([pd.Timestamp("2020-01-01"), pd.Timestamp("2020-01-02")]) df = ser.to_frame() with tm.assert_produces_warning(FutureWarning): result = df.shift(1, fill_value=0) - expected = pd.Series([pd.Timestamp(0), ser[0]]).to_frame() + expected = Series([pd.Timestamp(0), ser[0]]).to_frame() tm.assert_frame_equal(result, expected) # axis = 1 diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 9dab5f509bc75..9cf5afc09e800 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -131,9 +131,9 @@ def wrapper(x): r1 = getattr(all_na, opname)(axis=1) if opname in ["sum", "prod"]: unit = 1 if opname == "prod" else 0 # result for empty sum/prod - expected = pd.Series(unit, index=r0.index, dtype=r0.dtype) + expected = Series(unit, index=r0.index, dtype=r0.dtype) tm.assert_series_equal(r0, expected) - expected = pd.Series(unit, index=r1.index, dtype=r1.dtype) + expected = Series(unit, index=r1.index, dtype=r1.dtype) tm.assert_series_equal(r1, expected) @@ -466,7 +466,7 @@ def test_mean_mixed_datetime_numeric(self, tz): df = pd.DataFrame({"A": [1, 1], "B": [pd.Timestamp("2000", tz=tz)] * 2}) with tm.assert_produces_warning(FutureWarning): result = df.mean() - expected = pd.Series([1.0], index=["A"]) + expected = Series([1.0], index=["A"]) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("tz", [None, "UTC"]) @@ -478,7 +478,7 @@ def test_mean_excludes_datetimes(self, tz): with tm.assert_produces_warning(FutureWarning): result = df.mean() - expected = pd.Series(dtype=np.float64) + expected = Series(dtype=np.float64) tm.assert_series_equal(result, expected) def test_mean_mixed_string_decimal(self): @@ -501,7 +501,7 @@ def test_mean_mixed_string_decimal(self): df = pd.DataFrame(d) result = df.mean() - expected = pd.Series([2.7, 681.6], index=["A", "C"]) + expected = Series([2.7, 681.6], index=["A", "C"]) tm.assert_series_equal(result, expected) def test_var_std(self, datetime_frame): @@ -771,30 +771,30 @@ def test_sum_prod_nanops(self, method, unit): ) # The default result = getattr(df, method) - expected = pd.Series([unit, unit, unit], index=idx, dtype="float64") + expected = Series([unit, unit, unit], index=idx, dtype="float64") # min_count=1 result = getattr(df, method)(min_count=1) - expected = pd.Series([unit, unit, np.nan], index=idx) + expected = Series([unit, unit, np.nan], index=idx) tm.assert_series_equal(result, expected) # min_count=0 result = getattr(df, method)(min_count=0) - expected = pd.Series([unit, unit, unit], index=idx, dtype="float64") + expected = Series([unit, unit, unit], index=idx, dtype="float64") tm.assert_series_equal(result, expected) result = getattr(df.iloc[1:], method)(min_count=1) - expected = pd.Series([unit, np.nan, np.nan], index=idx) + expected = Series([unit, np.nan, np.nan], index=idx) tm.assert_series_equal(result, expected) # min_count > 1 df = pd.DataFrame({"A": [unit] * 10, "B": [unit] * 5 + [np.nan] * 5}) result = getattr(df, method)(min_count=5) - expected = pd.Series(result, index=["A", "B"]) + expected = Series(result, index=["A", "B"]) tm.assert_series_equal(result, expected) result = getattr(df, method)(min_count=6) - expected = pd.Series(result, index=["A", "B"]) + expected = Series(result, index=["A", "B"]) tm.assert_series_equal(result, expected) def test_sum_nanops_timedelta(self): @@ -806,7 +806,7 @@ def test_sum_nanops_timedelta(self): # 0 by default result = df2.sum() - expected = pd.Series([0, 0, 0], dtype="m8[ns]", index=idx) + expected = Series([0, 0, 0], dtype="m8[ns]", index=idx) tm.assert_series_equal(result, expected) # min_count=0 @@ -815,7 +815,7 @@ def test_sum_nanops_timedelta(self): # min_count=1 result = df2.sum(min_count=1) - expected = pd.Series([0, 0, np.nan], dtype="m8[ns]", index=idx) + expected = Series([0, 0, np.nan], dtype="m8[ns]", index=idx) tm.assert_series_equal(result, expected) def test_sum_object(self, float_frame): @@ -837,7 +837,7 @@ def test_sum_mixed_datetime(self): ).reindex([2, 3, 4]) result = df.sum() - expected = pd.Series({"B": 7.0}) + expected = Series({"B": 7.0}) tm.assert_series_equal(result, expected) def test_mean_corner(self, float_frame, float_string_frame): @@ -870,13 +870,13 @@ def test_mean_datetimelike(self): } ) result = df.mean(numeric_only=True) - expected = pd.Series({"A": 1.0}) + expected = Series({"A": 1.0}) tm.assert_series_equal(result, expected) with tm.assert_produces_warning(FutureWarning): # in the future datetime columns will be included result = df.mean() - expected = pd.Series({"A": 1.0, "C": df.loc[1, "C"]}) + expected = Series({"A": 1.0, "C": df.loc[1, "C"]}) tm.assert_series_equal(result, expected) def test_mean_datetimelike_numeric_only_false(self): @@ -890,7 +890,7 @@ def test_mean_datetimelike_numeric_only_false(self): # datetime(tz) and timedelta work result = df.mean(numeric_only=False) - expected = pd.Series({"A": 1, "B": df.loc[1, "B"], "C": df.loc[1, "C"]}) + expected = Series({"A": 1, "B": df.loc[1, "B"], "C": df.loc[1, "C"]}) tm.assert_series_equal(result, expected) # mean of period is not allowed @@ -1055,28 +1055,28 @@ def test_any_all_bool_only(self): (np.any, {"A": [False, False], "B": [False, True]}, True), (np.all, {"A": [False, False], "B": [False, True]}, False), # other types - (np.all, {"A": pd.Series([0.0, 1.0], dtype="float")}, False), - (np.any, {"A": pd.Series([0.0, 1.0], dtype="float")}, True), - (np.all, {"A": pd.Series([0, 1], dtype=int)}, False), - (np.any, {"A": pd.Series([0, 1], dtype=int)}, True), - pytest.param(np.all, {"A": pd.Series([0, 1], dtype="M8[ns]")}, False), - pytest.param(np.any, {"A": pd.Series([0, 1], dtype="M8[ns]")}, True), - pytest.param(np.all, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True), - pytest.param(np.any, {"A": pd.Series([1, 2], dtype="M8[ns]")}, True), - pytest.param(np.all, {"A": pd.Series([0, 1], dtype="m8[ns]")}, False), - pytest.param(np.any, {"A": pd.Series([0, 1], dtype="m8[ns]")}, True), - pytest.param(np.all, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True), - pytest.param(np.any, {"A": pd.Series([1, 2], dtype="m8[ns]")}, True), - (np.all, {"A": pd.Series([0, 1], dtype="category")}, False), - (np.any, {"A": pd.Series([0, 1], dtype="category")}, True), - (np.all, {"A": pd.Series([1, 2], dtype="category")}, True), - (np.any, {"A": pd.Series([1, 2], dtype="category")}, True), + (np.all, {"A": Series([0.0, 1.0], dtype="float")}, False), + (np.any, {"A": Series([0.0, 1.0], dtype="float")}, True), + (np.all, {"A": Series([0, 1], dtype=int)}, False), + (np.any, {"A": Series([0, 1], dtype=int)}, True), + pytest.param(np.all, {"A": Series([0, 1], dtype="M8[ns]")}, False), + pytest.param(np.any, {"A": Series([0, 1], dtype="M8[ns]")}, True), + pytest.param(np.all, {"A": Series([1, 2], dtype="M8[ns]")}, True), + pytest.param(np.any, {"A": Series([1, 2], dtype="M8[ns]")}, True), + pytest.param(np.all, {"A": Series([0, 1], dtype="m8[ns]")}, False), + pytest.param(np.any, {"A": Series([0, 1], dtype="m8[ns]")}, True), + pytest.param(np.all, {"A": Series([1, 2], dtype="m8[ns]")}, True), + pytest.param(np.any, {"A": Series([1, 2], dtype="m8[ns]")}, True), + (np.all, {"A": Series([0, 1], dtype="category")}, False), + (np.any, {"A": Series([0, 1], dtype="category")}, True), + (np.all, {"A": Series([1, 2], dtype="category")}, True), + (np.any, {"A": Series([1, 2], dtype="category")}, True), # Mix GH#21484 pytest.param( np.all, { - "A": pd.Series([10, 20], dtype="M8[ns]"), - "B": pd.Series([10, 20], dtype="m8[ns]"), + "A": Series([10, 20], dtype="M8[ns]"), + "B": Series([10, 20], dtype="m8[ns]"), }, True, ), @@ -1137,22 +1137,22 @@ def test_min_max_dt64_with_NaT(self): df = pd.DataFrame({"foo": [pd.NaT, pd.NaT, pd.Timestamp("2012-05-01")]}) res = df.min() - exp = pd.Series([pd.Timestamp("2012-05-01")], index=["foo"]) + exp = Series([pd.Timestamp("2012-05-01")], index=["foo"]) tm.assert_series_equal(res, exp) res = df.max() - exp = pd.Series([pd.Timestamp("2012-05-01")], index=["foo"]) + exp = Series([pd.Timestamp("2012-05-01")], index=["foo"]) tm.assert_series_equal(res, exp) # GH12941, only NaTs are in DataFrame. df = pd.DataFrame({"foo": [pd.NaT, pd.NaT]}) res = df.min() - exp = pd.Series([pd.NaT], index=["foo"]) + exp = Series([pd.NaT], index=["foo"]) tm.assert_series_equal(res, exp) res = df.max() - exp = pd.Series([pd.NaT], index=["foo"]) + exp = Series([pd.NaT], index=["foo"]) tm.assert_series_equal(res, exp) def test_min_max_dt64_api_consistency_with_NaT(self): @@ -1161,7 +1161,7 @@ def test_min_max_dt64_api_consistency_with_NaT(self): # min/max calls on empty Series/DataFrames. See GH:33704 for more # information df = pd.DataFrame(dict(x=pd.to_datetime([]))) - expected_dt_series = pd.Series(pd.to_datetime([])) + expected_dt_series = Series(pd.to_datetime([])) # check axis 0 assert (df.min(axis=0).x is pd.NaT) == (expected_dt_series.min() is pd.NaT) assert (df.max(axis=0).x is pd.NaT) == (expected_dt_series.max() is pd.NaT) @@ -1174,7 +1174,7 @@ def test_min_max_dt64_api_consistency_empty_df(self): # check DataFrame/Series api consistency when calling min/max on an empty # DataFrame/Series. df = pd.DataFrame(dict(x=[])) - expected_float_series = pd.Series([], dtype=float) + expected_float_series = Series([], dtype=float) # check axis 0 assert np.isnan(df.min(axis=0).x) == np.isnan(expected_float_series.min()) assert np.isnan(df.max(axis=0).x) == np.isnan(expected_float_series.max()) @@ -1201,7 +1201,7 @@ def test_mixed_frame_with_integer_sum(): df = pd.DataFrame([["a", 1]], columns=list("ab")) df = df.astype({"b": "Int64"}) result = df.sum() - expected = pd.Series(["a", 1], index=["a", "b"]) + expected = Series(["a", 1], index=["a", "b"]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/frame/test_arithmetic.py b/pandas/tests/frame/test_arithmetic.py index 2c04473d50851..74e6170d861b4 100644 --- a/pandas/tests/frame/test_arithmetic.py +++ b/pandas/tests/frame/test_arithmetic.py @@ -212,12 +212,12 @@ def _test_seq(df, idx_ser, col_ser): col_eq = df.eq(col_ser) idx_ne = df.ne(idx_ser, axis=0) col_ne = df.ne(col_ser) - tm.assert_frame_equal(col_eq, df == pd.Series(col_ser)) + tm.assert_frame_equal(col_eq, df == Series(col_ser)) tm.assert_frame_equal(col_eq, -col_ne) tm.assert_frame_equal(idx_eq, -idx_ne) tm.assert_frame_equal(idx_eq, df.T.eq(idx_ser).T) tm.assert_frame_equal(col_eq, df.eq(list(col_ser))) - tm.assert_frame_equal(idx_eq, df.eq(pd.Series(idx_ser), axis=0)) + tm.assert_frame_equal(idx_eq, df.eq(Series(idx_ser), axis=0)) tm.assert_frame_equal(idx_eq, df.eq(list(idx_ser), axis=0)) idx_gt = df.gt(idx_ser, axis=0) @@ -225,7 +225,7 @@ def _test_seq(df, idx_ser, col_ser): idx_le = df.le(idx_ser, axis=0) col_le = df.le(col_ser) - tm.assert_frame_equal(col_gt, df > pd.Series(col_ser)) + tm.assert_frame_equal(col_gt, df > Series(col_ser)) tm.assert_frame_equal(col_gt, -col_le) tm.assert_frame_equal(idx_gt, -idx_le) tm.assert_frame_equal(idx_gt, df.T.gt(idx_ser).T) @@ -234,13 +234,13 @@ def _test_seq(df, idx_ser, col_ser): col_ge = df.ge(col_ser) idx_lt = df.lt(idx_ser, axis=0) col_lt = df.lt(col_ser) - tm.assert_frame_equal(col_ge, df >= pd.Series(col_ser)) + tm.assert_frame_equal(col_ge, df >= Series(col_ser)) tm.assert_frame_equal(col_ge, -col_lt) tm.assert_frame_equal(idx_ge, -idx_lt) tm.assert_frame_equal(idx_ge, df.T.ge(idx_ser).T) - idx_ser = pd.Series(np.random.randn(5)) - col_ser = pd.Series(np.random.randn(3)) + idx_ser = Series(np.random.randn(5)) + col_ser = Series(np.random.randn(3)) _test_seq(df, idx_ser, col_ser) # list/tuple @@ -333,7 +333,7 @@ def test_df_flex_cmp_constant_return_types(self, opname): const = 2 result = getattr(df, opname)(const).dtypes.value_counts() - tm.assert_series_equal(result, pd.Series([2], index=[np.dtype(bool)])) + tm.assert_series_equal(result, Series([2], index=[np.dtype(bool)])) @pytest.mark.parametrize("opname", ["eq", "ne", "gt", "lt", "ge", "le"]) def test_df_flex_cmp_constant_return_types_empty(self, opname): @@ -343,19 +343,19 @@ def test_df_flex_cmp_constant_return_types_empty(self, opname): empty = df.iloc[:0] result = getattr(empty, opname)(const).dtypes.value_counts() - tm.assert_series_equal(result, pd.Series([2], index=[np.dtype(bool)])) + tm.assert_series_equal(result, Series([2], index=[np.dtype(bool)])) def test_df_flex_cmp_ea_dtype_with_ndarray_series(self): ii = pd.IntervalIndex.from_breaks([1, 2, 3]) df = pd.DataFrame({"A": ii, "B": ii}) - ser = pd.Series([0, 0]) + ser = Series([0, 0]) res = df.eq(ser, axis=0) expected = pd.DataFrame({"A": [False, False], "B": [False, False]}) tm.assert_frame_equal(res, expected) - ser2 = pd.Series([1, 2], index=["A", "B"]) + ser2 = Series([1, 2], index=["A", "B"]) res2 = df.eq(ser2, axis=1) tm.assert_frame_equal(res2, expected) @@ -368,7 +368,7 @@ class TestFrameFlexArithmetic: def test_floordiv_axis0(self): # make sure we df.floordiv(ser, axis=0) matches column-wise result arr = np.arange(3) - ser = pd.Series(arr) + ser = Series(arr) df = pd.DataFrame({"A": ser, "B": ser}) result = df.floordiv(ser, axis=0) @@ -403,7 +403,7 @@ def test_df_add_td64_columnwise(self): # GH 22534 Check that column-wise addition broadcasts correctly dti = pd.date_range("2016-01-01", periods=10) tdi = pd.timedelta_range("1", periods=10) - tser = pd.Series(tdi) + tser = Series(tdi) df = pd.DataFrame({0: dti, 1: tdi}) result = df.add(tser, axis=0) @@ -413,7 +413,7 @@ def test_df_add_td64_columnwise(self): def test_df_add_flex_filled_mixed_dtypes(self): # GH 19611 dti = pd.date_range("2016-01-01", periods=3) - ser = pd.Series(["1 Day", "NaT", "2 Days"], dtype="timedelta64[ns]") + ser = Series(["1 Day", "NaT", "2 Days"], dtype="timedelta64[ns]") df = pd.DataFrame({"A": dti, "B": ser}) other = pd.DataFrame({"A": ser, "B": ser}) fill = pd.Timedelta(days=1).to_timedelta64() @@ -421,7 +421,7 @@ def test_df_add_flex_filled_mixed_dtypes(self): expected = pd.DataFrame( { - "A": pd.Series( + "A": Series( ["2016-01-02", "2016-01-03", "2016-01-05"], dtype="datetime64[ns]" ), "B": ser * 2, @@ -544,7 +544,7 @@ def test_arith_flex_series(self, simple_frame): def test_arith_flex_zero_len_raises(self): # GH 19522 passing fill_value to frame flex arith methods should # raise even in the zero-length special cases - ser_len0 = pd.Series([], dtype=object) + ser_len0 = Series([], dtype=object) df_len0 = pd.DataFrame(columns=["A", "B"]) df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) @@ -568,7 +568,7 @@ class TestFrameArithmetic: def test_td64_op_nat_casting(self): # Make sure we don't accidentally treat timedelta64(NaT) as datetime64 # when calling dispatch_to_series in DataFrame arithmetic - ser = pd.Series(["NaT", "NaT"], dtype="timedelta64[ns]") + ser = Series(["NaT", "NaT"], dtype="timedelta64[ns]") df = pd.DataFrame([[1, 2], [3, 4]]) result = df * ser @@ -789,7 +789,7 @@ def test_frame_with_zero_len_series_corner_cases(): # GH#28600 # easy all-float case df = pd.DataFrame(np.random.randn(6).reshape(3, 2), columns=["A", "B"]) - ser = pd.Series(dtype=np.float64) + ser = Series(dtype=np.float64) result = df + ser expected = pd.DataFrame(df.values * np.nan, columns=df.columns) @@ -813,7 +813,7 @@ def test_frame_with_zero_len_series_corner_cases(): def test_zero_len_frame_with_series_corner_cases(): # GH#28600 df = pd.DataFrame(columns=["A", "B"], dtype=np.float64) - ser = pd.Series([1, 2], index=["A", "B"]) + ser = Series([1, 2], index=["A", "B"]) result = df + ser expected = df @@ -823,11 +823,11 @@ def test_zero_len_frame_with_series_corner_cases(): def test_frame_single_columns_object_sum_axis_1(): # GH 13758 data = { - "One": pd.Series(["A", 1.2, np.nan]), + "One": Series(["A", 1.2, np.nan]), } df = pd.DataFrame(data) result = df.sum(axis=1) - expected = pd.Series(["A", 1.2, 0]) + expected = Series(["A", 1.2, 0]) tm.assert_series_equal(result, expected) @@ -941,7 +941,7 @@ def test_binary_ops_align(self): midx = MultiIndex.from_product([["A", "B"], ["a", "b"]]) df = DataFrame(np.ones((2, 4), dtype="int64"), columns=midx) - s = pd.Series({"a": 1, "b": 2}) + s = Series({"a": 1, "b": 2}) df2 = df.copy() df2.columns.names = ["lvl0", "lvl1"] @@ -1521,7 +1521,7 @@ def test_pow_nan_with_zero(): def test_dataframe_series_extension_dtypes(): # https://github.com/pandas-dev/pandas/issues/34311 df = pd.DataFrame(np.random.randint(0, 100, (10, 3)), columns=["a", "b", "c"]) - ser = pd.Series([1, 2, 3], index=["a", "b", "c"]) + ser = Series([1, 2, 3], index=["a", "b", "c"]) expected = df.to_numpy("int64") + ser.to_numpy("int64").reshape(-1, 3) expected = pd.DataFrame(expected, columns=df.columns, dtype="Int64") @@ -1566,7 +1566,7 @@ def test_dataframe_operation_with_non_numeric_types(df, col_dtype): # GH #22663 expected = pd.DataFrame([[0.0, np.nan], [3.0, np.nan]], columns=list("ab")) expected = expected.astype({"b": col_dtype}) - result = df + pd.Series([-1.0], index=list("a")) + result = df + Series([-1.0], index=list("a")) tm.assert_frame_equal(result, expected) @@ -1579,9 +1579,7 @@ def test_arith_reindex_with_duplicates(): tm.assert_frame_equal(result, expected) -@pytest.mark.parametrize( - "to_add", [[pd.Series([1, 1])], [pd.Series([1, 1]), pd.Series([1, 1])]] -) +@pytest.mark.parametrize("to_add", [[Series([1, 1])], [Series([1, 1]), Series([1, 1])]]) def test_arith_list_of_arraylike_raise(to_add): # GH 36702. Raise when trying to add list of array-like to DataFrame df = pd.DataFrame({"x": [1, 2], "y": [1, 2]}) diff --git a/pandas/tests/frame/test_block_internals.py b/pandas/tests/frame/test_block_internals.py index f5d2bd27762ef..2877905ddced1 100644 --- a/pandas/tests/frame/test_block_internals.py +++ b/pandas/tests/frame/test_block_internals.py @@ -606,7 +606,7 @@ def test_strange_column_corruption_issue(self): def test_constructor_no_pandas_array(self): # Ensure that PandasArray isn't allowed inside Series # See https://github.com/pandas-dev/pandas/issues/23995 for more. - arr = pd.Series([1, 2, 3]).array + arr = Series([1, 2, 3]).array result = pd.DataFrame({"A": arr}) expected = pd.DataFrame({"A": [1, 2, 3]}) tm.assert_frame_equal(result, expected) @@ -648,7 +648,7 @@ def test_to_dict_of_blocks_item_cache(): def test_update_inplace_sets_valid_block_values(): # https://github.com/pandas-dev/pandas/issues/33457 - df = pd.DataFrame({"a": pd.Series([1, 2, None], dtype="category")}) + df = pd.DataFrame({"a": Series([1, 2, None], dtype="category")}) # inplace update of a single column df["a"].fillna(1, inplace=True) @@ -665,8 +665,8 @@ def test_nonconsolidated_item_cache_take(): # create non-consolidated dataframe with object dtype columns df = pd.DataFrame() - df["col1"] = pd.Series(["a"], dtype=object) - df["col2"] = pd.Series([0], dtype=object) + df["col1"] = Series(["a"], dtype=object) + df["col2"] = Series([0], dtype=object) # access column (item cache) df["col1"] == "A" diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index c6708a7b7f6c9..2bc6953217cf8 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1653,7 +1653,7 @@ def test_constructor_index_names(self, name_in1, name_in2, name_in3, name_out): pd.Index(["c", "d", "e"], name=name_in3), ] series = { - c: pd.Series([0, 1, 2], index=i) for i, c in zip(indices, ["x", "y", "z"]) + c: Series([0, 1, 2], index=i) for i, c in zip(indices, ["x", "y", "z"]) } result = pd.DataFrame(series) @@ -2566,7 +2566,7 @@ def test_from_records_series_categorical_index(self): index = CategoricalIndex( [pd.Interval(-20, -10), pd.Interval(-10, 0), pd.Interval(0, 10)] ) - series_of_dicts = pd.Series([{"a": 1}, {"a": 2}, {"b": 3}], index=index) + series_of_dicts = Series([{"a": 1}, {"a": 2}, {"b": 3}], index=index) frame = pd.DataFrame.from_records(series_of_dicts, index=index) expected = DataFrame( {"a": [1, 2, np.NaN], "b": [np.NaN, np.NaN, 3]}, index=index diff --git a/pandas/tests/frame/test_dtypes.py b/pandas/tests/frame/test_dtypes.py index 5917520802519..96e56c329475c 100644 --- a/pandas/tests/frame/test_dtypes.py +++ b/pandas/tests/frame/test_dtypes.py @@ -36,23 +36,21 @@ def test_concat_empty_dataframe_dtypes(self): def test_empty_frame_dtypes(self): empty_df = pd.DataFrame() - tm.assert_series_equal(empty_df.dtypes, pd.Series(dtype=object)) + tm.assert_series_equal(empty_df.dtypes, Series(dtype=object)) nocols_df = pd.DataFrame(index=[1, 2, 3]) - tm.assert_series_equal(nocols_df.dtypes, pd.Series(dtype=object)) + tm.assert_series_equal(nocols_df.dtypes, Series(dtype=object)) norows_df = pd.DataFrame(columns=list("abc")) - tm.assert_series_equal(norows_df.dtypes, pd.Series(object, index=list("abc"))) + tm.assert_series_equal(norows_df.dtypes, Series(object, index=list("abc"))) norows_int_df = pd.DataFrame(columns=list("abc")).astype(np.int32) tm.assert_series_equal( - norows_int_df.dtypes, pd.Series(np.dtype("int32"), index=list("abc")) + norows_int_df.dtypes, Series(np.dtype("int32"), index=list("abc")) ) df = pd.DataFrame(dict([("a", 1), ("b", True), ("c", 1.0)]), index=[1, 2, 3]) - ex_dtypes = pd.Series( - dict([("a", np.int64), ("b", np.bool_), ("c", np.float64)]) - ) + ex_dtypes = Series(dict([("a", np.int64), ("b", np.bool_), ("c", np.float64)])) tm.assert_series_equal(df.dtypes, ex_dtypes) # same but for empty slice of df @@ -85,14 +83,12 @@ def test_dtypes_are_correct_after_column_slice(self): df = pd.DataFrame(index=range(5), columns=list("abc"), dtype=np.float_) tm.assert_series_equal( df.dtypes, - pd.Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])), - ) - tm.assert_series_equal( - df.iloc[:, 2:].dtypes, pd.Series(dict([("c", np.float_)])) + Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])), ) + tm.assert_series_equal(df.iloc[:, 2:].dtypes, Series(dict([("c", np.float_)]))) tm.assert_series_equal( df.dtypes, - pd.Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])), + Series(dict([("a", np.float_), ("b", np.float_), ("c", np.float_)])), ) def test_dtypes_gh8722(self, float_string_frame): @@ -114,7 +110,7 @@ def test_singlerow_slice_categoricaldtype_gives_series(self): df = pd.DataFrame({"x": pd.Categorical("a b c d e".split())}) result = df.iloc[0] raw_cat = pd.Categorical(["a"], categories=["a", "b", "c", "d", "e"]) - expected = pd.Series(raw_cat, index=["x"], name=0, dtype="category") + expected = Series(raw_cat, index=["x"], name=0, dtype="category") tm.assert_series_equal(result, expected) @@ -257,15 +253,15 @@ def test_convert_dtypes(self, convert_integer, expected): # Just check that it works for DataFrame here df = pd.DataFrame( { - "a": pd.Series([1, 2, 3], dtype=np.dtype("int32")), - "b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")), + "a": Series([1, 2, 3], dtype=np.dtype("int32")), + "b": Series(["x", "y", "z"], dtype=np.dtype("O")), } ) result = df.convert_dtypes(True, True, convert_integer, False) expected = pd.DataFrame( { - "a": pd.Series([1, 2, 3], dtype=expected), - "b": pd.Series(["x", "y", "z"], dtype="string"), + "a": Series([1, 2, 3], dtype=expected), + "b": Series(["x", "y", "z"], dtype="string"), } ) tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 5d3f8e3a2f7c1..4b33fd7832cb8 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -131,7 +131,7 @@ def test_drop_and_dropna_caching(self): # tst that cacher updates original = Series([1, 2, np.nan], name="A") expected = Series([1, 2], dtype=original.dtype, name="A") - df = pd.DataFrame({"A": original.values.copy()}) + df = DataFrame({"A": original.values.copy()}) df2 = df.copy() df["A"].dropna() tm.assert_series_equal(df["A"], original) @@ -203,7 +203,7 @@ def test_dropna_categorical_interval_index(self): # GH 25087 ii = pd.IntervalIndex.from_breaks([0, 2.78, 3.14, 6.28]) ci = pd.CategoricalIndex(ii) - df = pd.DataFrame({"A": list("abc")}, index=ci) + df = DataFrame({"A": list("abc")}, index=ci) expected = df result = df.dropna() @@ -303,8 +303,8 @@ def test_fillna_datelike(self): def test_fillna_tzaware(self): # with timezone # GH#15855 - df = pd.DataFrame({"A": [pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.NaT]}) - exp = pd.DataFrame( + df = DataFrame({"A": [pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.NaT]}) + exp = DataFrame( { "A": [ pd.Timestamp("2012-11-11 00:00:00+01:00"), @@ -314,8 +314,8 @@ def test_fillna_tzaware(self): ) tm.assert_frame_equal(df.fillna(method="pad"), exp) - df = pd.DataFrame({"A": [pd.NaT, pd.Timestamp("2012-11-11 00:00:00+01:00")]}) - exp = pd.DataFrame( + df = DataFrame({"A": [pd.NaT, pd.Timestamp("2012-11-11 00:00:00+01:00")]}) + exp = DataFrame( { "A": [ pd.Timestamp("2012-11-11 00:00:00+01:00"), @@ -328,14 +328,14 @@ def test_fillna_tzaware(self): def test_fillna_tzaware_different_column(self): # with timezone in another column # GH#15522 - df = pd.DataFrame( + df = DataFrame( { "A": pd.date_range("20130101", periods=4, tz="US/Eastern"), "B": [1, 2, np.nan, np.nan], } ) result = df.fillna(method="pad") - expected = pd.DataFrame( + expected = DataFrame( { "A": pd.date_range("20130101", periods=4, tz="US/Eastern"), "B": [1.0, 2.0, 2.0, 2.0], @@ -378,7 +378,7 @@ def test_na_actions_categorical(self): # make sure that fillna takes missing values into account c = Categorical([np.nan, "b", np.nan], categories=["a", "b"]) - df = pd.DataFrame({"cats": c, "vals": [1, 2, 3]}) + df = DataFrame({"cats": c, "vals": [1, 2, 3]}) cat_exp = Categorical(["a", "b", "a"], categories=["a", "b"]) df_exp = DataFrame({"cats": cat_exp, "vals": [1, 2, 3]}) @@ -427,15 +427,15 @@ def test_fillna_categorical_nan(self): def test_fillna_downcast(self): # GH 15277 # infer int64 from float64 - df = pd.DataFrame({"a": [1.0, np.nan]}) + df = DataFrame({"a": [1.0, np.nan]}) result = df.fillna(0, downcast="infer") - expected = pd.DataFrame({"a": [1, 0]}) + expected = DataFrame({"a": [1, 0]}) tm.assert_frame_equal(result, expected) # infer int64 from float64 when fillna value is a dict - df = pd.DataFrame({"a": [1.0, np.nan]}) + df = DataFrame({"a": [1.0, np.nan]}) result = df.fillna({"a": 0}, downcast="infer") - expected = pd.DataFrame({"a": [1, 0]}) + expected = DataFrame({"a": [1, 0]}) tm.assert_frame_equal(result, expected) def test_fillna_dtype_conversion(self): @@ -464,7 +464,7 @@ def test_fillna_dtype_conversion(self): def test_fillna_datetime_columns(self): # GH 7095 - df = pd.DataFrame( + df = DataFrame( { "A": [-1, -2, np.nan], "B": date_range("20130101", periods=3), @@ -474,7 +474,7 @@ def test_fillna_datetime_columns(self): index=date_range("20130110", periods=3), ) result = df.fillna("?") - expected = pd.DataFrame( + expected = DataFrame( { "A": [-1, -2, "?"], "B": date_range("20130101", periods=3), @@ -485,7 +485,7 @@ def test_fillna_datetime_columns(self): ) tm.assert_frame_equal(result, expected) - df = pd.DataFrame( + df = DataFrame( { "A": [-1, -2, np.nan], "B": [pd.Timestamp("2013-01-01"), pd.Timestamp("2013-01-02"), pd.NaT], @@ -495,7 +495,7 @@ def test_fillna_datetime_columns(self): index=date_range("20130110", periods=3), ) result = df.fillna("?") - expected = pd.DataFrame( + expected = DataFrame( { "A": [-1, -2, "?"], "B": [pd.Timestamp("2013-01-01"), pd.Timestamp("2013-01-02"), "?"], diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index a8b76f4d85f49..172fcdc78e604 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -238,7 +238,7 @@ def check(result, expected=None): ) for index in [df.index, pd.Index(list("edcba"))]: this_df = df.copy() - expected_ser = pd.Series(index.values, index=this_df.index) + expected_ser = Series(index.values, index=this_df.index) expected_df = DataFrame( {"A": expected_ser, "B": this_df["B"], "A": expected_ser}, columns=["A", "B", "A"], diff --git a/pandas/tests/frame/test_reshape.py b/pandas/tests/frame/test_reshape.py index b10fdbb707404..67c53a56eebe9 100644 --- a/pandas/tests/frame/test_reshape.py +++ b/pandas/tests/frame/test_reshape.py @@ -182,7 +182,7 @@ def test_unstack_fill(self): unstacked = df.unstack(["x", "y"], fill_value=0) key = ("w", "b", "j") expected = unstacked[key] - result = pd.Series([0, 0, 2], index=unstacked.index, name=key) + result = Series([0, 0, 2], index=unstacked.index, name=key) tm.assert_series_equal(result, expected) stacked = unstacked.stack(["x", "y"]) @@ -315,7 +315,7 @@ def test_unstack_fill_frame_period(self): def test_unstack_fill_frame_categorical(self): # Test unstacking with categorical - data = pd.Series(["a", "b", "c", "a"], dtype="category") + data = Series(["a", "b", "c", "a"], dtype="category") data.index = pd.MultiIndex.from_tuples( [("x", "a"), ("x", "b"), ("y", "b"), ("z", "a")] ) @@ -427,15 +427,15 @@ def test_unstack_preserve_dtypes(self): dict( state=["IL", "MI", "NC"], index=["a", "b", "c"], - some_categories=pd.Series(["a", "b", "c"]).astype("category"), + some_categories=Series(["a", "b", "c"]).astype("category"), A=np.random.rand(3), B=1, C="foo", D=pd.Timestamp("20010102"), - E=pd.Series([1.0, 50.0, 100.0]).astype("float32"), - F=pd.Series([3.0, 4.0, 5.0]).astype("float64"), + E=Series([1.0, 50.0, 100.0]).astype("float32"), + F=Series([3.0, 4.0, 5.0]).astype("float64"), G=False, - H=pd.Series([1, 200, 923442], dtype="int8"), + H=Series([1, 200, 923442], dtype="int8"), ) ) @@ -586,7 +586,7 @@ def test_unstack_level_binding(self): codes=[[0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0]], names=["first", "second", "third"], ) - s = pd.Series(0, index=mi) + s = Series(0, index=mi) result = s.unstack([1, 2]).stack(0) expected_mi = pd.MultiIndex( @@ -1144,7 +1144,7 @@ def test_stack_preserve_categorical_dtype_values(self): df = pd.DataFrame({"A": cat, "B": cat}) result = df.stack() index = pd.MultiIndex.from_product([[0, 1, 2, 3], ["A", "B"]]) - expected = pd.Series( + expected = Series( pd.Categorical(["a", "a", "a", "a", "b", "b", "c", "c"]), index=index ) tm.assert_series_equal(result, expected) @@ -1186,7 +1186,7 @@ def test_unstack_mixed_extension_types(self, level): result = df.unstack(level=level) expected = df.astype(object).unstack(level=level) - expected_dtypes = pd.Series( + expected_dtypes = Series( [df.A.dtype] * 2 + [df.B.dtype] * 2, index=result.columns ) tm.assert_series_equal(result.dtypes, expected_dtypes) @@ -1213,7 +1213,7 @@ def test_unstack_swaplevel_sortlevel(self, level): def test_unstack_fill_frame_object(): # GH12815 Test unstacking with object. - data = pd.Series(["a", "b", "c", "a"], dtype="object") + data = Series(["a", "b", "c", "a"], dtype="object") data.index = pd.MultiIndex.from_tuples( [("x", "a"), ("x", "b"), ("y", "b"), ("z", "a")] ) @@ -1264,7 +1264,7 @@ def test_stack_timezone_aware_values(): ) df = pd.DataFrame({"A": ts}, index=["a", "b", "c"]) result = df.stack() - expected = pd.Series( + expected = Series( ts, index=pd.MultiIndex( levels=[["a", "b", "c"], ["A"]], codes=[[0, 1, 2], [0, 0, 0]] diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 2c2584e8dee01..fe1c476ed2205 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -604,7 +604,7 @@ def test_sample(sel): df.sample(n=1, axis="not_a_name") with pytest.raises(ValueError): - s = pd.Series(range(10)) + s = Series(range(10)) s.sample(n=1, axis=1) # Test weight length compared to correct axis @@ -890,7 +890,7 @@ def test_axis_numbers_deprecated(self, box): @pytest.mark.parametrize("as_frame", [True, False]) def test_flags_identity(self, as_frame): - s = pd.Series([1, 2]) + s = Series([1, 2]) if as_frame: s = s.to_frame() diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index 07c02330d85ce..0f8df5bb78304 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -37,7 +37,7 @@ def test_set_axis_name_mi(self, func): assert result.index.names, ["L1", "L2"] def test_set_axis_name_raises(self): - s = pd.Series([1]) + s = Series([1]) msg = "No axis named 1 for object type Series" with pytest.raises(ValueError, match=msg): s._set_axis_name(name="a", axis=1) @@ -166,7 +166,7 @@ class TestSeries2: [ Series([np.arange(5)]), pd.date_range("1/1/2011", periods=24, freq="H"), - pd.Series(range(5), index=pd.date_range("2017", periods=5)), + Series(range(5), index=pd.date_range("2017", periods=5)), ], ) @pytest.mark.parametrize("shift_size", [0, 1, 2]) @@ -177,5 +177,5 @@ def test_shift_always_copy(self, s, shift_size): @pytest.mark.parametrize("move_by_freq", [pd.Timedelta("1D"), pd.Timedelta("1M")]) def test_datetime_shift_always_copy(self, move_by_freq): # GH22397 - s = pd.Series(range(5), index=pd.date_range("2017", periods=5)) + s = Series(range(5), index=pd.date_range("2017", periods=5)) assert s.shift(freq=move_by_freq) is not s diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 4a0ea5f520873..c7a52dd45fadc 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -213,14 +213,10 @@ def test_aggregate_item_by_item(df): # GH5782 # odd comparisons can result here, so cast to make easy - exp = pd.Series( - np.array([foo] * K), index=list("BCD"), dtype=np.float64, name="foo" - ) + exp = Series(np.array([foo] * K), index=list("BCD"), dtype=np.float64, name="foo") tm.assert_series_equal(result.xs("foo"), exp) - exp = pd.Series( - np.array([bar] * K), index=list("BCD"), dtype=np.float64, name="bar" - ) + exp = Series(np.array([bar] * K), index=list("BCD"), dtype=np.float64, name="bar") tm.assert_almost_equal(result.xs("bar"), exp) def aggfun(ser): @@ -518,7 +514,7 @@ def test_agg_split_object_part_datetime(): class TestNamedAggregationSeries: def test_series_named_agg(self): - df = pd.Series([1, 2, 3, 4]) + df = Series([1, 2, 3, 4]) gr = df.groupby([0, 0, 1, 1]) result = gr.agg(a="sum", b="min") expected = pd.DataFrame( @@ -531,7 +527,7 @@ def test_series_named_agg(self): tm.assert_frame_equal(result, expected) def test_no_args_raises(self): - gr = pd.Series([1, 2]).groupby([0, 1]) + gr = Series([1, 2]).groupby([0, 1]) with pytest.raises(TypeError, match="Must provide"): gr.agg() @@ -542,13 +538,13 @@ def test_no_args_raises(self): def test_series_named_agg_duplicates_no_raises(self): # GH28426 - gr = pd.Series([1, 2, 3]).groupby([0, 0, 1]) + gr = Series([1, 2, 3]).groupby([0, 0, 1]) grouped = gr.agg(a="sum", b="sum") expected = pd.DataFrame({"a": [3, 3], "b": [3, 3]}) tm.assert_frame_equal(expected, grouped) def test_mangled(self): - gr = pd.Series([1, 2, 3]).groupby([0, 0, 1]) + gr = Series([1, 2, 3]).groupby([0, 0, 1]) result = gr.agg(a=lambda x: 0, b=lambda x: 1) expected = pd.DataFrame({"a": [0, 0], "b": [1, 1]}) tm.assert_frame_equal(result, expected) @@ -563,7 +559,7 @@ def test_mangled(self): ) def test_named_agg_nametuple(self, inp): # GH34422 - s = pd.Series([1, 1, 2, 2, 3, 3, 4, 5]) + s = Series([1, 1, 2, 2, 3, 3, 4, 5]) msg = f"func is expected but received {type(inp).__name__}" with pytest.raises(TypeError, match=msg): s.groupby(s.values).agg(a=inp) @@ -916,7 +912,7 @@ def test_groupby_aggregate_period_column(func): result = getattr(df.groupby("a")["b"], func)() idx = pd.Int64Index([1, 2], name="a") - expected = pd.Series(periods, index=idx, name="b") + expected = Series(periods, index=idx, name="b") tm.assert_series_equal(result, expected) @@ -947,7 +943,7 @@ def test_basic(self): tm.assert_frame_equal(result, expected) def test_mangle_series_groupby(self): - gr = pd.Series([1, 2, 3, 4]).groupby([0, 0, 1, 1]) + gr = Series([1, 2, 3, 4]).groupby([0, 0, 1, 1]) result = gr.agg([lambda x: 0, lambda x: 1]) expected = pd.DataFrame({"": [0, 0], "": [1, 1]}) tm.assert_frame_equal(result, expected) @@ -956,11 +952,11 @@ def test_mangle_series_groupby(self): def test_with_kwargs(self): f1 = lambda x, y, b=1: x.sum() + y + b f2 = lambda x, y, b=2: x.sum() + y * b - result = pd.Series([1, 2]).groupby([0, 0]).agg([f1, f2], 0) + result = Series([1, 2]).groupby([0, 0]).agg([f1, f2], 0) expected = pd.DataFrame({"": [4], "": [6]}) tm.assert_frame_equal(result, expected) - result = pd.Series([1, 2]).groupby([0, 0]).agg([f1, f2], 0, b=10) + result = Series([1, 2]).groupby([0, 0]).agg([f1, f2], 0, b=10) expected = pd.DataFrame({"": [13], "": [30]}) tm.assert_frame_equal(result, expected) @@ -1166,5 +1162,5 @@ def test_agg_no_suffix_index(): # test Series case result = df["A"].agg(["sum", lambda x: x.sum(), lambda x: x.sum()]) - expected = pd.Series([12, 12, 12], index=["sum", "", ""], name="A") + expected = Series([12, 12, 12], index=["sum", "", ""], name="A") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index e8cd6017a117c..a5f947cf656a0 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -130,11 +130,11 @@ def test_agg_dict_parameter_cast_result_dtypes(): tm.assert_series_equal(grouped.time.agg("last"), exp["time"]) # count - exp = pd.Series([2, 2, 2, 2], index=Index(list("ABCD"), name="class"), name="time") + exp = Series([2, 2, 2, 2], index=Index(list("ABCD"), name="class"), name="time") tm.assert_series_equal(grouped.time.agg(len), exp) tm.assert_series_equal(grouped.time.size(), exp) - exp = pd.Series([0, 1, 1, 2], index=Index(list("ABCD"), name="class"), name="time") + exp = Series([0, 1, 1, 2], index=Index(list("ABCD"), name="class"), name="time") tm.assert_series_equal(grouped.time.count(), exp) @@ -443,18 +443,18 @@ def test_agg_tzaware_non_datetime_result(): # Case that _does_ preserve the dtype result = gb["b"].agg(lambda x: x.iloc[0]) - expected = pd.Series(dti[::2], name="b") + expected = Series(dti[::2], name="b") expected.index.name = "a" tm.assert_series_equal(result, expected) # Cases that do _not_ preserve the dtype result = gb["b"].agg(lambda x: x.iloc[0].year) - expected = pd.Series([2012, 2012], name="b") + expected = Series([2012, 2012], name="b") expected.index.name = "a" tm.assert_series_equal(result, expected) result = gb["b"].agg(lambda x: x.iloc[-1] - x.iloc[0]) - expected = pd.Series([pd.Timedelta(days=1), pd.Timedelta(days=1)], name="b") + expected = Series([pd.Timedelta(days=1), pd.Timedelta(days=1)], name="b") expected.index.name = "a" tm.assert_series_equal(result, expected) @@ -542,10 +542,10 @@ def test_agg_structs_dataframe(structure, expected): @pytest.mark.parametrize( "structure, expected", [ - (tuple, pd.Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name="C")), - (list, pd.Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name="C")), - (lambda x: tuple(x), pd.Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name="C")), - (lambda x: list(x), pd.Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name="C")), + (tuple, Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name="C")), + (list, Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name="C")), + (lambda x: tuple(x), Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name="C")), + (lambda x: list(x), Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name="C")), ], ) def test_agg_structs_series(structure, expected): @@ -565,7 +565,7 @@ def test_agg_category_nansum(observed): {"A": pd.Categorical(["a", "a", "b"], categories=categories), "B": [1, 2, 3]} ) result = df.groupby("A", observed=observed).B.agg(np.nansum) - expected = pd.Series( + expected = Series( [3, 3, 0], index=pd.CategoricalIndex(["a", "b", "c"], categories=categories, name="A"), name="B", @@ -633,7 +633,7 @@ def test_groupby_agg_err_catching(err_cls): {"id1": [0, 0, 0, 1, 1], "id2": [0, 1, 0, 1, 1], "decimals": DecimalArray(data)} ) - expected = pd.Series(to_decimal([data[0], data[3]])) + expected = Series(to_decimal([data[0], data[3]])) def weird_func(x): # weird function that raise something other than TypeError or IndexError diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 176efdb6204da..feb758c82285d 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -568,7 +568,7 @@ def test_apply_reindex_values(): df = pd.DataFrame( {"group": ["Group1", "Group2"] * 2, "value": values}, index=indices ) - expected = pd.Series(values, index=indices, name="value") + expected = Series(values, index=indices, name="value") def reindex_helper(x): return x.reindex(np.arange(x.index.min(), x.index.max() + 1)) @@ -631,7 +631,7 @@ def get_B(g): # GH 14423 def predictions(tool): - out = pd.Series(index=["p1", "p2", "useTime"], dtype=object) + out = Series(index=["p1", "p2", "useTime"], dtype=object) if "step1" in list(tool.State): out["p1"] = str(tool[tool.State == "step1"].Machine.values[0]) if "step2" in list(tool.State): @@ -666,7 +666,7 @@ def test_apply_aggregating_timedelta_and_datetime(): ) df["time_delta_zero"] = df.datetime - df.datetime result = df.groupby("clientid").apply( - lambda ddf: pd.Series( + lambda ddf: Series( dict(clientid_age=ddf.time_delta_zero.min(), date=ddf.datetime.min()) ) ) @@ -707,10 +707,10 @@ def test_time_field_bug(): df = pd.DataFrame({"a": 1, "b": [datetime.now() for nn in range(10)]}) def func_with_no_date(batch): - return pd.Series({"c": 2}) + return Series({"c": 2}) def func_with_date(batch): - return pd.Series({"b": datetime(2015, 1, 1), "c": 2}) + return Series({"b": datetime(2015, 1, 1), "c": 2}) dfg_no_conversion = df.groupby(by=["a"]).apply(func_with_no_date) dfg_no_conversion_expected = pd.DataFrame({"c": 2}, index=[1]) @@ -791,7 +791,7 @@ def test_groupby_apply_return_empty_chunk(): df = pd.DataFrame(dict(value=[0, 1], group=["filled", "empty"])) groups = df.groupby("group") result = groups.apply(lambda group: group[group.value != 1]["value"]) - expected = pd.Series( + expected = Series( [0], name="value", index=MultiIndex.from_product( @@ -836,7 +836,7 @@ def test_apply_datetime_issue(group_column_dtlike): # standard int values in range(len(num_columns)) df = pd.DataFrame({"a": ["foo"], "b": [group_column_dtlike]}) - result = df.groupby("a").apply(lambda x: pd.Series(["spam"], index=[42])) + result = df.groupby("a").apply(lambda x: Series(["spam"], index=[42])) expected = pd.DataFrame( ["spam"], Index(["foo"], dtype="object", name="a"), columns=[42] @@ -876,7 +876,7 @@ def most_common_values(df): return Series({c: s.value_counts().index[0] for c, s in df.iteritems()}) result = tdf.groupby("day").apply(most_common_values)["userId"] - expected = pd.Series( + expected = Series( ["17661101"], index=pd.DatetimeIndex(["2015-02-24"], name="day"), name="userId" ) tm.assert_series_equal(result, expected) @@ -955,7 +955,7 @@ def test_apply_function_returns_non_pandas_non_scalar(function, expected_values) # GH 31441 df = pd.DataFrame(["A", "A", "B", "B"], columns=["groups"]) result = df.groupby("groups").apply(function) - expected = pd.Series(expected_values, index=pd.Index(["A", "B"], name="groups")) + expected = Series(expected_values, index=pd.Index(["A", "B"], name="groups")) tm.assert_series_equal(result, expected) @@ -967,7 +967,7 @@ def fct(group): df = pd.DataFrame({"A": ["a", "a", "b", "none"], "B": [1, 2, 3, np.nan]}) result = df.groupby("A").apply(fct) - expected = pd.Series( + expected = Series( [[1.0, 2.0], [3.0], [np.nan]], index=pd.Index(["a", "b", "none"], name="A") ) tm.assert_series_equal(result, expected) @@ -978,7 +978,7 @@ def test_apply_function_index_return(function): # GH: 22541 df = pd.DataFrame([1, 2, 2, 2, 1, 2, 3, 1, 3, 1], columns=["id"]) result = df.groupby("id").apply(function) - expected = pd.Series( + expected = Series( [pd.Index([0, 4, 7, 9]), pd.Index([1, 2, 3, 5]), pd.Index([6, 8])], index=pd.Index([1, 2, 3], name="id"), ) @@ -996,7 +996,7 @@ def fn(x): return x.col2 result = df.groupby(["col1"], as_index=False).apply(fn) - expected = pd.Series( + expected = Series( [1, 2, 0, 4, 5, 0], index=pd.MultiIndex.from_tuples( [(0, 0), (0, 1), (0, 2), (1, 3), (1, 4), (1, 5)] diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 711daf7fe415d..ab211845c1957 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -470,13 +470,13 @@ def test_observed_groups_with_nan(observed): def test_observed_nth(): # GH 26385 cat = pd.Categorical(["a", np.nan, np.nan], categories=["a", "b", "c"]) - ser = pd.Series([1, 2, 3]) + ser = Series([1, 2, 3]) df = pd.DataFrame({"cat": cat, "ser": ser}) result = df.groupby("cat", observed=False)["ser"].nth(0) index = pd.Categorical(["a", "b", "c"], categories=["a", "b", "c"]) - expected = pd.Series([1, np.nan, np.nan], index=index, name="ser") + expected = Series([1, np.nan, np.nan], index=index, name="ser") expected.index.name = "cat" tm.assert_series_equal(result, expected) @@ -772,7 +772,7 @@ def test_preserve_on_ordered_ops(func, values): g = df.groupby("payload") result = getattr(g, func)() expected = pd.DataFrame( - {"payload": [-2, -1], "col": pd.Series(values, dtype=c.dtype)} + {"payload": [-2, -1], "col": Series(values, dtype=c.dtype)} ).set_index("payload") tm.assert_frame_equal(result, expected) @@ -822,9 +822,9 @@ def test_groupby_empty_with_category(): {"A": [None] * 3, "B": pd.Categorical(["train", "train", "test"])} ) result = df.groupby("A").first()["B"] - expected = pd.Series( + expected = Series( pd.Categorical([], categories=["test", "train"]), - index=pd.Series([], dtype="object", name="A"), + index=Series([], dtype="object", name="A"), name="B", ) tm.assert_series_equal(result, expected) @@ -1472,11 +1472,11 @@ def test_groupy_first_returned_categorical_instead_of_dataframe(func): # GH 28641: groupby drops index, when grouping over categorical column with # first/last. Renamed Categorical instead of DataFrame previously. df = pd.DataFrame( - {"A": [1997], "B": pd.Series(["b"], dtype="category").cat.as_ordered()} + {"A": [1997], "B": Series(["b"], dtype="category").cat.as_ordered()} ) df_grouped = df.groupby("A")["B"] result = getattr(df_grouped, func)() - expected = pd.Series(["b"], index=pd.Index([1997], name="A"), name="B") + expected = Series(["b"], index=pd.Index([1997], name="A"), name="B") tm.assert_series_equal(result, expected) @@ -1543,7 +1543,7 @@ def test_agg_cython_category_not_implemented_fallback(): df["col_cat"] = df["col_num"].astype("category") result = df.groupby("col_num").col_cat.first() - expected = pd.Series( + expected = Series( [1, 2, 3], index=pd.Index([1, 2, 3], name="col_num"), name="col_cat" ) tm.assert_series_equal(result, expected) @@ -1556,7 +1556,7 @@ def test_agg_cython_category_not_implemented_fallback(): @pytest.mark.parametrize("func", ["min", "max"]) def test_aggregate_categorical_lost_index(func: str): # GH: 28641 groupby drops index, when grouping over categorical column with min/max - ds = pd.Series(["b"], dtype="category").cat.as_ordered() + ds = Series(["b"], dtype="category").cat.as_ordered() df = pd.DataFrame({"A": [1997], "B": ds}) result = df.groupby("A").agg({"B": func}) expected = pd.DataFrame({"B": ["b"]}, index=pd.Index([1997], name="A")) @@ -1652,8 +1652,8 @@ def test_series_groupby_first_on_categorical_col_grouped_on_2_categoricals( idx = pd.Categorical([0, 1]) idx = pd.MultiIndex.from_product([idx, idx], names=["a", "b"]) expected_dict = { - "first": pd.Series([0, np.NaN, np.NaN, 1], idx, name="c"), - "last": pd.Series([1, np.NaN, np.NaN, 0], idx, name="c"), + "first": Series([0, np.NaN, np.NaN, 1], idx, name="c"), + "last": Series([1, np.NaN, np.NaN, 0], idx, name="c"), } expected = expected_dict[func] @@ -1677,8 +1677,8 @@ def test_df_groupby_first_on_categorical_col_grouped_on_2_categoricals( idx = pd.Categorical([0, 1]) idx = pd.MultiIndex.from_product([idx, idx], names=["a", "b"]) expected_dict = { - "first": pd.Series([0, np.NaN, np.NaN, 1], idx, name="c"), - "last": pd.Series([1, np.NaN, np.NaN, 0], idx, name="c"), + "first": Series([0, np.NaN, np.NaN, 1], idx, name="c"), + "last": Series([1, np.NaN, np.NaN, 0], idx, name="c"), } expected = expected_dict[func].to_frame() diff --git a/pandas/tests/groupby/test_counting.py b/pandas/tests/groupby/test_counting.py index 997d9b006c802..a5842dee2c43e 100644 --- a/pandas/tests/groupby/test_counting.py +++ b/pandas/tests/groupby/test_counting.py @@ -303,12 +303,12 @@ def test_count_non_nulls(): def test_count_object(): df = pd.DataFrame({"a": ["a"] * 3 + ["b"] * 3, "c": [2] * 3 + [3] * 3}) result = df.groupby("c").a.count() - expected = pd.Series([3, 3], index=pd.Index([2, 3], name="c"), name="a") + expected = Series([3, 3], index=pd.Index([2, 3], name="c"), name="a") tm.assert_series_equal(result, expected) df = pd.DataFrame({"a": ["a", np.nan, np.nan] + ["b"] * 3, "c": [2] * 3 + [3] * 3}) result = df.groupby("c").a.count() - expected = pd.Series([1, 3], index=pd.Index([2, 3], name="c"), name="a") + expected = Series([1, 3], index=pd.Index([2, 3], name="c"), name="a") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index c16ad812eb634..ad2e61ad99389 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -7,9 +7,9 @@ def test_filter_series(): - s = pd.Series([1, 3, 20, 5, 22, 24, 7]) - expected_odd = pd.Series([1, 3, 5, 7], index=[0, 1, 3, 6]) - expected_even = pd.Series([20, 22, 24], index=[2, 4, 5]) + s = Series([1, 3, 20, 5, 22, 24, 7]) + expected_odd = Series([1, 3, 5, 7], index=[0, 1, 3, 6]) + expected_even = Series([20, 22, 24], index=[2, 4, 5]) grouper = s.apply(lambda x: x % 2) grouped = s.groupby(grouper) tm.assert_series_equal(grouped.filter(lambda x: x.mean() < 10), expected_odd) @@ -63,7 +63,7 @@ def test_filter_mixed_df(): def test_filter_out_all_groups(): - s = pd.Series([1, 3, 20, 5, 22, 24, 7]) + s = Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) grouped = s.groupby(grouper) tm.assert_series_equal(grouped.filter(lambda x: x.mean() > 1000), s[[]]) @@ -74,7 +74,7 @@ def test_filter_out_all_groups(): def test_filter_out_no_groups(): - s = pd.Series([1, 3, 20, 5, 22, 24, 7]) + s = Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) grouped = s.groupby(grouper) filtered = grouped.filter(lambda x: x.mean() > 0) @@ -108,7 +108,7 @@ def raise_if_sum_is_zero(x): else: return x.sum() > 0 - s = pd.Series([-1, 0, 1, 2]) + s = Series([-1, 0, 1, 2]) grouper = s.apply(lambda x: x % 2) grouped = s.groupby(grouper) msg = "the filter must return a boolean result" @@ -586,12 +586,12 @@ def test_filter_non_bool_raises(): def test_filter_dropna_with_empty_groups(): # GH 10780 - data = pd.Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3)) + data = Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3)) groupped = data.groupby(level=0) result_false = groupped.filter(lambda x: x.mean() > 1, dropna=False) - expected_false = pd.Series([np.nan] * 9, index=np.repeat([1, 2, 3], 3)) + expected_false = Series([np.nan] * 9, index=np.repeat([1, 2, 3], 3)) tm.assert_series_equal(result_false, expected_false) result_true = groupped.filter(lambda x: x.mean() > 1, dropna=True) - expected_true = pd.Series(index=pd.Index([], dtype=int), dtype=np.float64) + expected_true = Series(index=pd.Index([], dtype=int), dtype=np.float64) tm.assert_series_equal(result_true, expected_true) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index ab736b55b5743..7a309db143758 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -88,13 +88,13 @@ def test_max_min_non_numeric(): def test_min_date_with_nans(): # GH26321 dates = pd.to_datetime( - pd.Series(["2019-05-09", "2019-05-09", "2019-05-09"]), format="%Y-%m-%d" + Series(["2019-05-09", "2019-05-09", "2019-05-09"]), format="%Y-%m-%d" ).dt.date df = pd.DataFrame({"a": [np.nan, "1", np.nan], "b": [0, 1, 1], "c": dates}) result = df.groupby("b", as_index=False)["c"].min()["c"] expected = pd.to_datetime( - pd.Series(["2019-05-09", "2019-05-09"], name="c"), format="%Y-%m-%d" + Series(["2019-05-09", "2019-05-09"], name="c"), format="%Y-%m-%d" ).dt.date tm.assert_series_equal(result, expected) @@ -157,7 +157,7 @@ def test_arg_passthru(): "int": [1, 2, 3], "float": [4.0, 5.0, 6.0], "string": list("abc"), - "category_string": pd.Series(list("abc")).astype("category"), + "category_string": Series(list("abc")).astype("category"), "category_int": [7, 8, 9], "datetime": pd.date_range("20130101", periods=3), "datetimetz": pd.date_range("20130101", periods=3, tz="US/Eastern"), @@ -695,7 +695,7 @@ def test_cummin(numpy_dtypes_for_minmax): # GH 15561 df = pd.DataFrame(dict(a=[1], b=pd.to_datetime(["2001"]))) - expected = pd.Series(pd.to_datetime("2001"), index=[0], name="b") + expected = Series(pd.to_datetime("2001"), index=[0], name="b") result = df.groupby("a")["b"].cummin() tm.assert_series_equal(expected, result) @@ -703,7 +703,7 @@ def test_cummin(numpy_dtypes_for_minmax): # GH 15635 df = pd.DataFrame(dict(a=[1, 2, 1], b=[1, 2, 2])) result = df.groupby("a").b.cummin() - expected = pd.Series([1, 2, 1], name="b") + expected = Series([1, 2, 1], name="b") tm.assert_series_equal(result, expected) @@ -753,7 +753,7 @@ def test_cummax(numpy_dtypes_for_minmax): # GH 15561 df = pd.DataFrame(dict(a=[1], b=pd.to_datetime(["2001"]))) - expected = pd.Series(pd.to_datetime("2001"), index=[0], name="b") + expected = Series(pd.to_datetime("2001"), index=[0], name="b") result = df.groupby("a")["b"].cummax() tm.assert_series_equal(expected, result) @@ -761,7 +761,7 @@ def test_cummax(numpy_dtypes_for_minmax): # GH 15635 df = pd.DataFrame(dict(a=[1, 2, 1], b=[2, 1, 1])) result = df.groupby("a").b.cummax() - expected = pd.Series([2, 1, 2], name="b") + expected = Series([2, 1, 2], name="b") tm.assert_series_equal(result, expected) @@ -803,7 +803,7 @@ def test_is_monotonic_increasing(in_vals, out_vals): df = pd.DataFrame(source_dict) result = df.groupby("B").C.is_monotonic_increasing index = Index(list("abcd"), name="B") - expected = pd.Series(index=index, data=out_vals, name="C") + expected = Series(index=index, data=out_vals, name="C") tm.assert_series_equal(result, expected) # Also check result equal to manually taking x.is_monotonic_increasing. @@ -840,7 +840,7 @@ def test_is_monotonic_decreasing(in_vals, out_vals): df = pd.DataFrame(source_dict) result = df.groupby("B").C.is_monotonic_decreasing index = Index(list("abcd"), name="B") - expected = pd.Series(index=index, data=out_vals, name="C") + expected = Series(index=index, data=out_vals, name="C") tm.assert_series_equal(result, expected) @@ -1054,7 +1054,7 @@ def test_groupby_sum_below_mincount_nullable_integer(): idx = pd.Index([0, 1, 2], dtype=object, name="a") result = grouped["b"].sum(min_count=2) - expected = pd.Series([pd.NA] * 3, dtype="Int64", index=idx, name="b") + expected = Series([pd.NA] * 3, dtype="Int64", index=idx, name="b") tm.assert_series_equal(result, expected) result = grouped.sum(min_count=2) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 087b4f64307e6..a1c00eb5f38f5 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -596,11 +596,11 @@ def test_as_index_select_column(): # GH 5764 df = pd.DataFrame([[1, 2], [1, 4], [5, 6]], columns=["A", "B"]) result = df.groupby("A", as_index=False)["B"].get_group(1) - expected = pd.Series([2, 4], name="B") + expected = Series([2, 4], name="B") tm.assert_series_equal(result, expected) result = df.groupby("A", as_index=False)["B"].apply(lambda x: x.cumsum()) - expected = pd.Series( + expected = Series( [2, 6, 6], name="B", index=pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 2)]) ) tm.assert_series_equal(result, expected) @@ -1188,7 +1188,7 @@ def test_groupby_unit64_float_conversion(): #  GH: 30859 groupby converts unit64 to floats sometimes df = pd.DataFrame({"first": [1], "second": [1], "value": [16148277970000000000]}) result = df.groupby(["first", "second"])["value"].max() - expected = pd.Series( + expected = Series( [16148277970000000000], pd.MultiIndex.from_product([[1], [1]], names=["first", "second"]), name="value", @@ -1775,7 +1775,7 @@ def test_tuple_as_grouping(): df[["a", "b", "c"]].groupby(("a", "b")) result = df.groupby(("a", "b"))["c"].sum() - expected = pd.Series([4], name="c", index=pd.Index([1], name=("a", "b"))) + expected = Series([4], name="c", index=pd.Index([1], name=("a", "b"))) tm.assert_series_equal(result, expected) @@ -1824,10 +1824,10 @@ def test_groupby_multiindex_nat(): (datetime(2012, 1, 3), "a"), ] mi = pd.MultiIndex.from_tuples(values, names=["date", None]) - ser = pd.Series([3, 2, 2.5, 4], index=mi) + ser = Series([3, 2, 2.5, 4], index=mi) result = ser.groupby(level=1).mean() - expected = pd.Series([3.0, 2.5], index=["a", "b"]) + expected = Series([3.0, 2.5], index=["a", "b"]) tm.assert_series_equal(result, expected) @@ -1845,13 +1845,13 @@ def test_groupby_multiindex_series_keys_len_equal_group_axis(): index_array = [["x", "x"], ["a", "b"], ["k", "k"]] index_names = ["first", "second", "third"] ri = pd.MultiIndex.from_arrays(index_array, names=index_names) - s = pd.Series(data=[1, 2], index=ri) + s = Series(data=[1, 2], index=ri) result = s.groupby(["first", "third"]).sum() index_array = [["x"], ["k"]] index_names = ["first", "third"] ei = pd.MultiIndex.from_arrays(index_array, names=index_names) - expected = pd.Series([3], index=ei) + expected = Series([3], index=ei) tm.assert_series_equal(result, expected) @@ -1963,18 +1963,18 @@ def test_groupby_only_none_group(): # this was crashing with "ValueError: Length of passed values is 1, index implies 0" df = pd.DataFrame({"g": [None], "x": 1}) actual = df.groupby("g")["x"].transform("sum") - expected = pd.Series([np.nan], name="x") + expected = Series([np.nan], name="x") tm.assert_series_equal(actual, expected) def test_groupby_duplicate_index(): # GH#29189 the groupby call here used to raise - ser = pd.Series([2, 5, 6, 8], index=[2.0, 4.0, 4.0, 5.0]) + ser = Series([2, 5, 6, 8], index=[2.0, 4.0, 4.0, 5.0]) gb = ser.groupby(level=0) result = gb.mean() - expected = pd.Series([2, 5.5, 8], index=[2.0, 4.0, 5.0]) + expected = Series([2, 5.5, 8], index=[2.0, 4.0, 5.0]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 18ef95c05f291..3b3967b858adf 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -615,15 +615,15 @@ def test_list_grouper_with_nat(self): [ ( "transform", - pd.Series(name=2, dtype=np.float64, index=pd.RangeIndex(0, 0, 1)), + Series(name=2, dtype=np.float64, index=pd.RangeIndex(0, 0, 1)), ), ( "agg", - pd.Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)), + Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)), ), ( "apply", - pd.Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)), + Series(name=2, dtype=np.float64, index=pd.Float64Index([], name=1)), ), ], ) @@ -639,7 +639,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", dtype="float64") + s = Series([], name="name", dtype="float64") gr = s.groupby([]) result = gr.mean() @@ -778,7 +778,7 @@ def test_get_group_grouped_by_tuple(self): def test_groupby_with_empty(self): index = pd.DatetimeIndex(()) data = () - series = pd.Series(data, index, dtype=object) + series = Series(data, index, dtype=object) grouper = pd.Grouper(freq="D") grouped = series.groupby(grouper) assert next(iter(grouped), None) is None diff --git a/pandas/tests/groupby/test_missing.py b/pandas/tests/groupby/test_missing.py index 70d8dfc20822a..2c2147795bc07 100644 --- a/pandas/tests/groupby/test_missing.py +++ b/pandas/tests/groupby/test_missing.py @@ -9,7 +9,7 @@ @pytest.mark.parametrize("func", ["ffill", "bfill"]) def test_groupby_column_index_name_lost_fill_funcs(func): # GH: 29764 groupby loses index sometimes - df = pd.DataFrame( + df = DataFrame( [[1, 1.0, -1.0], [1, np.nan, np.nan], [1, 2.0, -2.0]], columns=pd.Index(["type", "a", "b"], name="idx"), ) @@ -22,10 +22,10 @@ def test_groupby_column_index_name_lost_fill_funcs(func): @pytest.mark.parametrize("func", ["ffill", "bfill"]) def test_groupby_fill_duplicate_column_names(func): # GH: 25610 ValueError with duplicate column names - df1 = pd.DataFrame({"field1": [1, 3, 4], "field2": [1, 3, 4]}) - df2 = pd.DataFrame({"field1": [1, np.nan, 4]}) + df1 = DataFrame({"field1": [1, 3, 4], "field2": [1, 3, 4]}) + df2 = DataFrame({"field1": [1, np.nan, 4]}) df_grouped = pd.concat([df1, df2], axis=1).groupby(by=["field2"]) - expected = pd.DataFrame( + expected = DataFrame( [[1, 1.0], [3, np.nan], [4, 4.0]], columns=["field1", "field1"] ) result = getattr(df_grouped, func)() @@ -34,7 +34,7 @@ def test_groupby_fill_duplicate_column_names(func): def test_ffill_missing_arguments(): # GH 14955 - df = pd.DataFrame({"a": [1, 2], "b": [1, 1]}) + df = DataFrame({"a": [1, 2], "b": [1, 1]}) with pytest.raises(ValueError, match="Must specify a fill"): df.groupby("b").fillna() @@ -90,7 +90,7 @@ def test_fill_consistency(): def test_ffill_handles_nan_groups(dropna, method, has_nan_group): # GH 34725 - df_without_nan_rows = pd.DataFrame([(1, 0.1), (2, 0.2)]) + df_without_nan_rows = DataFrame([(1, 0.1), (2, 0.2)]) ridx = [-1, 0, -1, -1, 1, -1] df = df_without_nan_rows.reindex(ridx).reset_index(drop=True) diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index 0cbfbad85a8b6..7dd37163021ed 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -142,7 +142,7 @@ def test_first_last_nth_dtypes(df_mixed_floats): def test_first_last_nth_nan_dtype(): # GH 33591 - df = pd.DataFrame({"data": ["A"], "nans": pd.Series([np.nan], dtype=object)}) + df = pd.DataFrame({"data": ["A"], "nans": Series([np.nan], dtype=object)}) grouped = df.groupby("data") expected = df.set_index("data").nans @@ -386,7 +386,7 @@ def test_first_last_tz(data, expected_first, expected_last): ) def test_first_last_tz_multi_column(method, ts, alpha): # GH 21603 - category_string = pd.Series(list("abc")).astype("category") + category_string = Series(list("abc")).astype("category") df = pd.DataFrame( { "group": [1, 1, 2], diff --git a/pandas/tests/groupby/test_nunique.py b/pandas/tests/groupby/test_nunique.py index c3347b7ae52f3..8e37ac1a1a21d 100644 --- a/pandas/tests/groupby/test_nunique.py +++ b/pandas/tests/groupby/test_nunique.py @@ -96,15 +96,15 @@ def test_nunique_with_object(): result = data.groupby(["id", "amount"])["name"].nunique() index = MultiIndex.from_arrays([data.id, data.amount]) - expected = pd.Series([1] * 5, name="name", index=index) + expected = Series([1] * 5, name="name", index=index) tm.assert_series_equal(result, expected) def test_nunique_with_empty_series(): # GH 12553 - data = pd.Series(name="name", dtype=object) + data = Series(name="name", dtype=object) result = data.groupby(level=0).nunique() - expected = pd.Series(name="name", dtype="int64") + expected = Series(name="name", dtype="int64") tm.assert_series_equal(result, expected) @@ -173,5 +173,5 @@ def test_nunique_transform_with_datetime(): # GH 35109 - transform with nunique on datetimes results in integers df = pd.DataFrame(date_range("2008-12-31", "2009-01-02"), columns=["date"]) result = df.groupby([0, 0, 1])["date"].transform("nunique") - expected = pd.Series([2, 2, 1], name="date") + expected = Series([2, 2, 1], name="date") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 4ccbc6a65fd88..4693fe360c819 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -408,7 +408,7 @@ def test_timegrouper_apply_return_type_series(self): df_dt["date"] = pd.to_datetime(df_dt["date"]) def sumfunc_series(x): - return pd.Series([x["value"].sum()], ("sum",)) + return Series([x["value"].sum()], ("sum",)) expected = df.groupby(pd.Grouper(key="date")).apply(sumfunc_series) result = df_dt.groupby(pd.Grouper(freq="M", key="date")).apply(sumfunc_series) @@ -754,7 +754,7 @@ def test_scalar_call_versus_list_call(self): # Issue: 17530 data_frame = { "location": ["shanghai", "beijing", "shanghai"], - "time": pd.Series( + "time": Series( ["2017-08-09 13:32:23", "2017-08-11 23:23:15", "2017-08-11 22:23:15"], dtype="datetime64[ns]", ), @@ -776,10 +776,10 @@ def test_grouper_period_index(self): index = pd.period_range( start="2018-01", periods=periods, freq="M", name="Month" ) - period_series = pd.Series(range(periods), index=index) + period_series = Series(range(periods), index=index) result = period_series.groupby(period_series.index.month).sum() - expected = pd.Series( + expected = Series( range(0, periods), index=Index(range(1, periods + 1), name=index.name) ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/groupby/transform/test_transform.py b/pandas/tests/groupby/transform/test_transform.py index 97be039e16ebb..4b79701a57acd 100644 --- a/pandas/tests/groupby/transform/test_transform.py +++ b/pandas/tests/groupby/transform/test_transform.py @@ -87,7 +87,7 @@ def test_transform_fast(): grp = df.groupby("id")["val"] values = np.repeat(grp.mean().values, ensure_platform_int(grp.count().values)) - expected = pd.Series(values, index=df.index, name="val") + expected = Series(values, index=df.index, name="val") result = grp.transform(np.mean) tm.assert_series_equal(result, expected) @@ -221,7 +221,7 @@ def test_transform_bug(): def test_transform_numeric_to_boolean(): # GH 16875 # inconsistency in transforming boolean values - expected = pd.Series([True, True], name="A") + expected = Series([True, True], name="A") df = pd.DataFrame({"A": [1.1, 2.2], "B": [1, 2]}) result = df.groupby("B").A.transform(lambda x: True) @@ -236,7 +236,7 @@ def test_transform_datetime_to_timedelta(): # GH 15429 # transforming a datetime to timedelta df = DataFrame(dict(A=Timestamp("20130101"), B=np.arange(5))) - expected = pd.Series([Timestamp("20130101") - Timestamp("20130101")] * 5, name="A") + expected = Series([Timestamp("20130101") - Timestamp("20130101")] * 5, name="A") # this does date math without changing result type in transform base_time = df["A"][0] @@ -399,14 +399,14 @@ def test_series_fast_transform_date(): pd.Timestamp("2014-1-2"), pd.Timestamp("2014-1-4"), ] - expected = pd.Series(dates, name="d") + expected = Series(dates, name="d") tm.assert_series_equal(result, expected) def test_transform_length(): # GH 9697 df = pd.DataFrame({"col1": [1, 1, 2, 2], "col2": [1, 2, 3, np.nan]}) - expected = pd.Series([3.0] * 4) + expected = Series([3.0] * 4) def nsum(x): return np.nansum(x) @@ -484,9 +484,7 @@ def test_groupby_transform_with_nan_group(): # GH 9941 df = pd.DataFrame({"a": range(10), "b": [1, 1, 2, 3, np.nan, 4, 4, 5, 5, 5]}) result = df.groupby(df.b)["a"].transform(max) - expected = pd.Series( - [1.0, 1.0, 2.0, 3.0, np.nan, 6.0, 6.0, 9.0, 9.0, 9.0], name="a" - ) + expected = Series([1.0, 1.0, 2.0, 3.0, np.nan, 6.0, 6.0, 9.0, 9.0, 9.0], name="a") tm.assert_series_equal(result, expected) @@ -625,7 +623,7 @@ def test_cython_transform_series(op, args, targop): "input, exp", [ # When everything is NaN - ({"key": ["b"] * 10, "value": np.nan}, pd.Series([np.nan] * 10, name="value")), + ({"key": ["b"] * 10, "value": np.nan}, Series([np.nan] * 10, name="value")), # When there is a single NaN ( {"key": ["b"] * 10 + ["a"] * 2, "value": [3] * 3 + [np.nan] + [3] * 8}, @@ -671,7 +669,7 @@ def test_groupby_cum_skipna(op, skipna, input, exp): expected = exp[(op, skipna)] else: expected = exp - expected = pd.Series(expected, name="value") + expected = Series(expected, name="value") tm.assert_series_equal(expected, result) @@ -792,7 +790,7 @@ def test_transform_with_non_scalar_group(): @pytest.mark.parametrize( "cols,exp,comp_func", [ - ("a", pd.Series([1, 1, 1], name="a"), tm.assert_series_equal), + ("a", Series([1, 1, 1], name="a"), tm.assert_series_equal), ( ["a", "c"], pd.DataFrame({"a": [1, 1, 1], "c": [1, 1, 1]}), @@ -984,7 +982,7 @@ def test_any_all_np_func(func): [["foo", True], [np.nan, True], ["foo", True]], columns=["key", "val"] ) - exp = pd.Series([True, np.nan, True], name="val") + exp = Series([True, np.nan, True], name="val") res = df.groupby("key")["val"].transform(func) tm.assert_series_equal(res, exp) @@ -1037,7 +1035,7 @@ def test_groupby_transform_with_datetimes(func, values): result = stocks.groupby(stocks["week_id"])["price"].transform(func) - expected = pd.Series(data=pd.to_datetime(values), index=dates, name="price") + expected = Series(data=pd.to_datetime(values), index=dates, name="price") tm.assert_series_equal(result, expected) @@ -1237,5 +1235,5 @@ def test_categorical_and_not_categorical_key(observed): ) expected = df_without_categorical.groupby(["A", "C"])["B"].transform("sum") tm.assert_series_equal(result, expected) - expected_explicit = pd.Series([4, 2, 4], name="B") + expected_explicit = Series([4, 2, 4], name="B") tm.assert_series_equal(result, expected_explicit) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index bc178c138341f..d6d8854f4f78a 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -803,7 +803,7 @@ def test_map(self): "mapper", [ lambda values, index: {i: e for e, i in zip(values, index)}, - lambda values, index: pd.Series(values, index), + lambda values, index: Series(values, index), ], ) def test_map_dictlike(self, mapper): diff --git a/pandas/tests/indexes/datetimes/test_ops.py b/pandas/tests/indexes/datetimes/test_ops.py index ea6381547009c..ada4902f6900b 100644 --- a/pandas/tests/indexes/datetimes/test_ops.py +++ b/pandas/tests/indexes/datetimes/test_ops.py @@ -328,7 +328,7 @@ def test_equals(self): assert idx.astype(object).equals(idx) assert idx.astype(object).equals(idx.astype(object)) assert not idx.equals(list(idx)) - assert not idx.equals(pd.Series(idx)) + assert not idx.equals(Series(idx)) idx2 = pd.DatetimeIndex(["2011-01-01", "2011-01-02", "NaT"], tz="US/Pacific") assert not idx.equals(idx2) @@ -336,7 +336,7 @@ def test_equals(self): assert not idx.equals(idx2.astype(object)) assert not idx.astype(object).equals(idx2) assert not idx.equals(list(idx2)) - assert not idx.equals(pd.Series(idx2)) + assert not idx.equals(Series(idx2)) # same internal, different tz idx3 = pd.DatetimeIndex(idx.asi8, tz="US/Pacific") @@ -346,7 +346,7 @@ def test_equals(self): assert not idx.equals(idx3.astype(object)) assert not idx.astype(object).equals(idx3) assert not idx.equals(list(idx3)) - assert not idx.equals(pd.Series(idx3)) + assert not idx.equals(Series(idx3)) # check that we do not raise when comparing with OutOfBounds objects oob = pd.Index([datetime(2500, 1, 1)] * 3, dtype=object) diff --git a/pandas/tests/indexes/multi/test_constructors.py b/pandas/tests/indexes/multi/test_constructors.py index 16af884c89e9e..70580f0a83f83 100644 --- a/pandas/tests/indexes/multi/test_constructors.py +++ b/pandas/tests/indexes/multi/test_constructors.py @@ -196,7 +196,7 @@ def test_from_arrays_index_series_datetimetz(): tm.assert_index_equal(result.get_level_values(0), idx1) tm.assert_index_equal(result.get_level_values(1), idx2) - result2 = pd.MultiIndex.from_arrays([pd.Series(idx1), pd.Series(idx2)]) + result2 = pd.MultiIndex.from_arrays([Series(idx1), Series(idx2)]) tm.assert_index_equal(result2.get_level_values(0), idx1) tm.assert_index_equal(result2.get_level_values(1), idx2) @@ -210,7 +210,7 @@ def test_from_arrays_index_series_timedelta(): tm.assert_index_equal(result.get_level_values(0), idx1) tm.assert_index_equal(result.get_level_values(1), idx2) - result2 = pd.MultiIndex.from_arrays([pd.Series(idx1), pd.Series(idx2)]) + result2 = pd.MultiIndex.from_arrays([Series(idx1), Series(idx2)]) tm.assert_index_equal(result2.get_level_values(0), idx1) tm.assert_index_equal(result2.get_level_values(1), idx2) @@ -224,7 +224,7 @@ def test_from_arrays_index_series_period(): tm.assert_index_equal(result.get_level_values(0), idx1) tm.assert_index_equal(result.get_level_values(1), idx2) - result2 = pd.MultiIndex.from_arrays([pd.Series(idx1), pd.Series(idx2)]) + result2 = pd.MultiIndex.from_arrays([Series(idx1), Series(idx2)]) tm.assert_index_equal(result2.get_level_values(0), idx1) tm.assert_index_equal(result2.get_level_values(1), idx2) @@ -244,7 +244,7 @@ def test_from_arrays_index_datetimelike_mixed(): tm.assert_index_equal(result.get_level_values(3), idx4) result2 = pd.MultiIndex.from_arrays( - [pd.Series(idx1), pd.Series(idx2), pd.Series(idx3), pd.Series(idx4)] + [Series(idx1), Series(idx2), Series(idx3), Series(idx4)] ) tm.assert_index_equal(result2.get_level_values(0), idx1) tm.assert_index_equal(result2.get_level_values(1), idx2) @@ -263,7 +263,7 @@ def test_from_arrays_index_series_categorical(): tm.assert_index_equal(result.get_level_values(0), idx1) tm.assert_index_equal(result.get_level_values(1), idx2) - result2 = pd.MultiIndex.from_arrays([pd.Series(idx1), pd.Series(idx2)]) + result2 = pd.MultiIndex.from_arrays([Series(idx1), Series(idx2)]) tm.assert_index_equal(result2.get_level_values(0), idx1) tm.assert_index_equal(result2.get_level_values(1), idx2) @@ -340,8 +340,8 @@ def test_from_arrays_different_lengths(idx1, idx2): def test_from_arrays_respects_none_names(): # GH27292 - a = pd.Series([1, 2, 3], name="foo") - b = pd.Series(["a", "b", "c"], name="bar") + a = Series([1, 2, 3], name="foo") + b = Series(["a", "b", "c"], name="bar") result = MultiIndex.from_arrays([a, b], names=None) expected = MultiIndex( @@ -478,7 +478,7 @@ def test_from_product_datetimeindex(): @pytest.mark.parametrize("ordered", [False, True]) -@pytest.mark.parametrize("f", [lambda x: x, lambda x: pd.Series(x), lambda x: x.values]) +@pytest.mark.parametrize("f", [lambda x: x, lambda x: Series(x), lambda x: x.values]) def test_from_product_index_series_categorical(ordered, f): # GH13743 first = ["foo", "bar"] @@ -547,11 +547,11 @@ def test_from_product_iterator(): "a, b, expected_names", [ ( - pd.Series([1, 2, 3], name="foo"), - pd.Series(["a", "b"], name="bar"), + Series([1, 2, 3], name="foo"), + Series(["a", "b"], name="bar"), ["foo", "bar"], ), - (pd.Series([1, 2, 3], name="foo"), ["a", "b"], ["foo", None]), + (Series([1, 2, 3], name="foo"), ["a", "b"], ["foo", None]), ([1, 2, 3], ["a", "b"], None), ], ) @@ -568,8 +568,8 @@ def test_from_product_infer_names(a, b, expected_names): def test_from_product_respects_none_names(): # GH27292 - a = pd.Series([1, 2, 3], name="foo") - b = pd.Series(["a", "b"], name="bar") + a = Series([1, 2, 3], name="foo") + b = Series(["a", "b"], name="bar") result = MultiIndex.from_product([a, b], names=None) expected = MultiIndex( @@ -649,7 +649,7 @@ def test_from_frame(): @pytest.mark.parametrize( "non_frame", [ - pd.Series([1, 2, 3, 4]), + Series([1, 2, 3, 4]), [1, 2, 3, 4], [[1, 2], [3, 4], [5, 6]], pd.Index([1, 2, 3, 4]), diff --git a/pandas/tests/indexes/multi/test_equivalence.py b/pandas/tests/indexes/multi/test_equivalence.py index fec1c0e44cd9f..e1b011b762fe7 100644 --- a/pandas/tests/indexes/multi/test_equivalence.py +++ b/pandas/tests/indexes/multi/test_equivalence.py @@ -20,7 +20,7 @@ def test_equals(idx): if idx.nlevels == 1: # do not test MultiIndex - assert not idx.equals(pd.Series(idx)) + assert not idx.equals(Series(idx)) def test_equals_op(idx): @@ -258,11 +258,11 @@ def test_multiindex_compare(): midx = pd.MultiIndex.from_product([[0, 1]]) # Equality self-test: MultiIndex object vs self - expected = pd.Series([True, True]) - result = pd.Series(midx == midx) + expected = Series([True, True]) + result = Series(midx == midx) tm.assert_series_equal(result, expected) # Greater than comparison: MultiIndex object vs self - expected = pd.Series([False, False]) - result = pd.Series(midx > midx) + expected = Series([False, False]) + result = Series(midx > midx) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index f85f37e4127c3..678967db72a0b 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -5,7 +5,6 @@ from pandas.core.dtypes.dtypes import PeriodDtype -import pandas as pd from pandas import ( Index, NaT, @@ -195,7 +194,7 @@ def test_constructor_datetime64arr_ok(self, box): if box is None: data = data._values elif box == "series": - data = pd.Series(data) + data = Series(data) result = PeriodIndex(data, freq="D") expected = PeriodIndex( @@ -362,7 +361,7 @@ def test_constructor_nat(self): period_range(start="2011-01-01", end="NaT", freq="M") def test_constructor_year_and_quarter(self): - year = pd.Series([2001, 2002, 2003]) + year = Series([2001, 2002, 2003]) quarter = year - 2000 idx = PeriodIndex(year=year, quarter=quarter) strs = [f"{t[0]:d}Q{t[1]:d}" for t in zip(quarter, year)] diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index 85a01f1c5278c..b6d3c36f1682c 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -143,10 +143,10 @@ def test_getitem_nat(self): assert idx[0] == Period("2011-01", freq="M") assert idx[1] is NaT - s = pd.Series([0, 1, 2], index=idx) + s = Series([0, 1, 2], index=idx) assert s[NaT] == 1 - s = pd.Series(idx, index=idx) + s = Series(idx, index=idx) assert s[Period("2011-01", freq="M")] == Period("2011-01", freq="M") assert s[NaT] is NaT @@ -366,7 +366,7 @@ def test_get_loc_invalid_string_raises_keyerror(self): with pytest.raises(KeyError, match="A"): pi.get_loc("A") - ser = pd.Series([1, 2, 3], index=pi) + ser = Series([1, 2, 3], index=pi) with pytest.raises(KeyError, match="A"): ser.loc["A"] @@ -687,7 +687,7 @@ def test_get_value(self): p2 = Period("2017-09-03") idx0 = PeriodIndex([p0, p1, p2]) - input0 = pd.Series(np.array([1, 2, 3]), index=idx0) + input0 = Series(np.array([1, 2, 3]), index=idx0) expected0 = 2 with tm.assert_produces_warning(FutureWarning): @@ -695,7 +695,7 @@ def test_get_value(self): assert result0 == expected0 idx1 = PeriodIndex([p1, p1, p2]) - input1 = pd.Series(np.array([1, 2, 3]), index=idx1) + input1 = Series(np.array([1, 2, 3]), index=idx1) expected1 = input1.iloc[[0, 1]] with tm.assert_produces_warning(FutureWarning): @@ -703,7 +703,7 @@ def test_get_value(self): tm.assert_series_equal(result1, expected1) idx2 = PeriodIndex([p1, p2, p1]) - input2 = pd.Series(np.array([1, 2, 3]), index=idx2) + input2 = Series(np.array([1, 2, 3]), index=idx2) expected2 = input2.iloc[[0, 2]] with tm.assert_produces_warning(FutureWarning): @@ -713,7 +713,7 @@ def test_get_value(self): def test_loc_str(self): # https://github.com/pandas-dev/pandas/issues/33964 index = pd.period_range(start="2000", periods=20, freq="B") - series = pd.Series(range(20), index=index) + series = Series(range(20), index=index) assert series.loc["2000-01-14"] == 9 @pytest.mark.parametrize("freq", ["H", "D"]) @@ -721,7 +721,7 @@ def test_get_value_datetime_hourly(self, freq): # get_loc and get_value should treat datetime objects symmetrically dti = date_range("2016-01-01", periods=3, freq="MS") pi = dti.to_period(freq) - ser = pd.Series(range(7, 10), index=pi) + ser = Series(range(7, 10), index=pi) ts = dti[0] @@ -753,14 +753,14 @@ def test_get_value_integer(self): msg = "index 16801 is out of bounds for axis 0 with size 3" dti = date_range("2016-01-01", periods=3) pi = dti.to_period("D") - ser = pd.Series(range(3), index=pi) + ser = Series(range(3), index=pi) with pytest.raises(IndexError, match=msg): with tm.assert_produces_warning(FutureWarning): pi.get_value(ser, 16801) msg = "index 46 is out of bounds for axis 0 with size 3" pi2 = dti.to_period("Y") # duplicates, ordinals are all 46 - ser2 = pd.Series(range(3), index=pi2) + ser2 = Series(range(3), index=pi2) with pytest.raises(IndexError, match=msg): with tm.assert_produces_warning(FutureWarning): pi2.get_value(ser2, 46) @@ -776,7 +776,7 @@ def test_contains(self): ps0 = [p0, p1, p2] idx0 = PeriodIndex(ps0) - ser = pd.Series(range(6, 9), index=idx0) + ser = Series(range(6, 9), index=idx0) for p in ps0: assert p in idx0 diff --git a/pandas/tests/indexes/period/test_ops.py b/pandas/tests/indexes/period/test_ops.py index d1b34c315b682..74ca6ec59736b 100644 --- a/pandas/tests/indexes/period/test_ops.py +++ b/pandas/tests/indexes/period/test_ops.py @@ -297,7 +297,7 @@ def test_equals(self, freq): assert idx.astype(object).equals(idx) assert idx.astype(object).equals(idx.astype(object)) assert not idx.equals(list(idx)) - assert not idx.equals(pd.Series(idx)) + assert not idx.equals(Series(idx)) idx2 = pd.PeriodIndex(["2011-01-01", "2011-01-02", "NaT"], freq="H") assert not idx.equals(idx2) @@ -305,7 +305,7 @@ def test_equals(self, freq): assert not idx.equals(idx2.astype(object)) assert not idx.astype(object).equals(idx2) assert not idx.equals(list(idx2)) - assert not idx.equals(pd.Series(idx2)) + assert not idx.equals(Series(idx2)) # same internal, different tz idx3 = pd.PeriodIndex._simple_new( @@ -317,7 +317,7 @@ def test_equals(self, freq): assert not idx.equals(idx3.astype(object)) assert not idx.astype(object).equals(idx3) assert not idx.equals(list(idx3)) - assert not idx.equals(pd.Series(idx3)) + assert not idx.equals(Series(idx3)) def test_freq_setter_deprecated(self): # GH 20678 diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 085d41aaa5b76..8467fde0f7021 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -256,7 +256,7 @@ def _check_all_fields(self, periodindex): ] periods = list(periodindex) - s = pd.Series(periodindex) + s = Series(periodindex) for field in fields: field_idx = getattr(periodindex, field) @@ -307,9 +307,9 @@ def test_period_reindex_with_object( period_index = PeriodIndex(p_values) object_index = Index(o_values) - s = pd.Series(values, index=period_index) + s = Series(values, index=period_index) result = s.reindex(object_index) - expected = pd.Series(expected_values, index=object_index) + expected = Series(expected_values, index=object_index) tm.assert_series_equal(result, expected) def test_is_(self): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 8db1bcc84bfa6..0e963531810df 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -137,7 +137,7 @@ def test_constructor_from_index_dtlike(self, cast_as_obj, index): ], ) def test_constructor_from_series_dtlike(self, index, has_tz): - result = pd.Index(pd.Series(index)) + result = pd.Index(Series(index)) tm.assert_index_equal(result, index) if has_tz: @@ -168,7 +168,7 @@ def test_constructor_from_frame_series_freq(self): expected.name = "date" tm.assert_index_equal(result, expected) - expected = pd.Series(dts, name="date") + expected = Series(dts, name="date") tm.assert_series_equal(df["date"], expected) # GH 6274 @@ -215,7 +215,7 @@ def test_constructor_int_dtype_nan_raises(self, dtype): Index(data, dtype=dtype) def test_constructor_no_pandas_array(self): - ser = pd.Series([1, 2, 3]) + ser = Series([1, 2, 3]) result = pd.Index(ser.array) expected = pd.Index([1, 2, 3]) tm.assert_index_equal(result, expected) @@ -879,7 +879,7 @@ def test_map_tseries_indices_accsr_return_index(self): "mapper", [ lambda values, index: {i: e for e, i in zip(values, index)}, - lambda values, index: pd.Series(values, index), + lambda values, index: Series(values, index), ], ) def test_map_dictlike_simple(self, mapper): @@ -893,7 +893,7 @@ def test_map_dictlike_simple(self, mapper): "mapper", [ lambda values, index: {i: e for e, i in zip(values, index)}, - lambda values, index: pd.Series(values, index), + lambda values, index: Series(values, index), ], ) def test_map_dictlike(self, index, mapper): @@ -2584,7 +2584,7 @@ def test_validate_1d_input(): # GH#13601 trying to assign a multi-dimensional array to an index is not # allowed - ser = pd.Series(0, range(4)) + ser = Series(0, range(4)) with pytest.raises(ValueError, match=msg): ser.index = np.array([[2, 3]] * 4) diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index 3e452e7e2841d..c4429137d17f0 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -72,7 +72,7 @@ def test_nonunique_contains(self): def test_unknown_attribute(self): # see gh-9680 tdi = pd.timedelta_range(start=0, periods=10, freq="1s") - ts = pd.Series(np.random.normal(size=10), index=tdi) + ts = Series(np.random.normal(size=10), index=tdi) assert "foo" not in ts.__dict__.keys() msg = "'Series' object has no attribute 'foo'" with pytest.raises(AttributeError, match=msg): @@ -237,7 +237,7 @@ def test_equals(self): assert idx.astype(object).equals(idx) assert idx.astype(object).equals(idx.astype(object)) assert not idx.equals(list(idx)) - assert not idx.equals(pd.Series(idx)) + assert not idx.equals(Series(idx)) idx2 = pd.TimedeltaIndex(["2 days", "1 days", "NaT"]) assert not idx.equals(idx2) @@ -246,7 +246,7 @@ def test_equals(self): assert not idx.astype(object).equals(idx2) assert not idx.astype(object).equals(idx2.astype(object)) assert not idx.equals(list(idx2)) - assert not idx.equals(pd.Series(idx2)) + assert not idx.equals(Series(idx2)) # Check that we dont raise OverflowError on comparisons outside the # implementation range diff --git a/pandas/tests/indexing/interval/test_interval.py b/pandas/tests/indexing/interval/test_interval.py index 8976e87a1b75a..1f3f59d038ce9 100644 --- a/pandas/tests/indexing/interval/test_interval.py +++ b/pandas/tests/indexing/interval/test_interval.py @@ -146,5 +146,5 @@ def test_mi_intervalindex_slicing_with_scalar(self): idx = pd.MultiIndex.from_arrays([query_df.Item, query_df.RID, query_df.MP]) query_df.index = idx result = df.value.loc[query_df.index] - expected = pd.Series([1, 6, 2, 8, 7], index=idx, name="value") + expected = Series([1, 6, 2, 8, 7], index=idx, name="value") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/indexing/multiindex/test_loc.py b/pandas/tests/indexing/multiindex/test_loc.py index 518ec9e997183..6072400d06a36 100644 --- a/pandas/tests/indexing/multiindex/test_loc.py +++ b/pandas/tests/indexing/multiindex/test_loc.py @@ -463,7 +463,7 @@ def test_loc_period_string_indexing(): ), ) result = df.loc[("2013Q1", 1111), "OMS"] - expected = pd.Series( + expected = Series( [np.nan], dtype=object, name="OMS", @@ -482,7 +482,7 @@ def test_loc_datetime_mask_slicing(): data=[[1, 2], [3, 4], [5, 6], [7, 6]], index=m_idx, columns=["C1", "C2"] ) result = df.loc[(dt_idx[0], (df.index.get_level_values(1) > "2017-05-04")), "C1"] - expected = pd.Series( + expected = Series( [3], name="C1", index=MultiIndex.from_tuples( @@ -496,7 +496,7 @@ def test_loc_datetime_mask_slicing(): def test_loc_datetime_series_tuple_slicing(): # https://github.com/pandas-dev/pandas/issues/35858 date = pd.Timestamp("2000") - ser = pd.Series( + ser = Series( 1, index=pd.MultiIndex.from_tuples([("a", date)], names=["a", "b"]), name="c", @@ -546,7 +546,7 @@ def test_3levels_leading_period_index(): lev3 = ["B", "C", "Q", "F"] mi = pd.MultiIndex.from_arrays([pi, lev2, lev3]) - ser = pd.Series(range(4), index=mi, dtype=np.float64) + ser = Series(range(4), index=mi, dtype=np.float64) result = ser.loc[(pi[0], "A", "B")] assert result == 0.0 @@ -562,7 +562,7 @@ def test_missing_keys_raises_keyerror(self): def test_missing_key_raises_keyerror2(self): # GH#21168 KeyError, not "IndexingError: Too many indexers" - ser = pd.Series(-1, index=pd.MultiIndex.from_product([[0, 1]] * 2)) + ser = Series(-1, index=pd.MultiIndex.from_product([[0, 1]] * 2)) with pytest.raises(KeyError, match=r"\(0, 3\)"): ser.loc[0, 3] diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py index ec0391a2ccc26..c1b41c6f5d8cf 100644 --- a/pandas/tests/indexing/multiindex/test_slice.py +++ b/pandas/tests/indexing/multiindex/test_slice.py @@ -528,7 +528,7 @@ def test_loc_ax_single_level_indexer_simple_df(self): # test single level indexing on single index column data frame df = pd.DataFrame(np.arange(9).reshape(3, 3), columns=["a", "b", "c"]) result = df.loc(axis=1)["a"] - expected = pd.Series(np.array([0, 3, 6]), name="a") + expected = Series(np.array([0, 3, 6]), name="a") tm.assert_series_equal(result, expected) def test_per_axis_per_level_setitem(self): diff --git a/pandas/tests/indexing/test_categorical.py b/pandas/tests/indexing/test_categorical.py index fae229aecc3d4..347ce2262a261 100644 --- a/pandas/tests/indexing/test_categorical.py +++ b/pandas/tests/indexing/test_categorical.py @@ -733,7 +733,7 @@ def test_map_with_dict_or_series(self): new_values, name="XXX", categories=[3.0, 2, "one"] ) - mapper = pd.Series(new_values[:-1], index=orig_values[:-1]) + mapper = Series(new_values[:-1], index=orig_values[:-1]) output = cur_index.map(mapper) # Order of categories in output can be different tm.assert_index_equal(expected, output) diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 752ecd47fe089..04790cdf6cc9d 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -124,7 +124,7 @@ def test_setitem_series_int8(self, val, exp_dtype, request): exp = pd.Series([1, 0, 3, 4], dtype=np.int8) self._assert_setitem_series_conversion(obj, val, exp, np.int8) mark = pytest.mark.xfail( - reason="BUG: it must be Series([1, 1, 3, 4], dtype=np.int16" + reason="BUG: it must be pd.Series([1, 1, 3, 4], dtype=np.int16" ) request.node.add_marker(mark) diff --git a/pandas/tests/indexing/test_datetime.py b/pandas/tests/indexing/test_datetime.py index ad71b6b72df33..f5e6aea5f8db8 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -302,7 +302,7 @@ def test_loc_getitem_across_dst(self): idx = pd.date_range( "2017-10-29 01:30:00", tz="Europe/Berlin", periods=5, freq="30 min" ) - series2 = pd.Series([0, 1, 2, 3, 4], index=idx) + series2 = Series([0, 1, 2, 3, 4], index=idx) t_1 = pd.Timestamp( "2017-10-29 02:30:00+02:00", tz="Europe/Berlin", freq="30min" @@ -311,7 +311,7 @@ def test_loc_getitem_across_dst(self): "2017-10-29 02:00:00+01:00", tz="Europe/Berlin", freq="30min" ) result = series2.loc[t_1:t_2] - expected = pd.Series([2, 3], index=idx[2:4]) + expected = Series([2, 3], index=idx[2:4]) tm.assert_series_equal(result, expected) result = series2[t_1] @@ -322,10 +322,10 @@ def test_loc_incremental_setitem_with_dst(self): # GH 20724 base = datetime(2015, 11, 1, tzinfo=tz.gettz("US/Pacific")) idxs = [base + timedelta(seconds=i * 900) for i in range(16)] - result = pd.Series([0], index=[idxs[0]]) + result = Series([0], index=[idxs[0]]) for ts in idxs: result.loc[ts] = 1 - expected = pd.Series(1, index=idxs) + expected = Series(1, index=idxs) tm.assert_series_equal(result, expected) def test_loc_setitem_with_existing_dst(self): @@ -372,7 +372,7 @@ def test_loc_label_slicing(self): ) def test_getitem_slice_date(self, slice_, positions): # https://github.com/pandas-dev/pandas/issues/31501 - s = pd.Series( + s = Series( [0, 1, 2], pd.DatetimeIndex(["2019-01-01", "2019-01-01T06:00:00", "2019-01-02"]), ) diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index d3d455f83c41a..f94f1d6aa453f 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -51,7 +51,7 @@ class TestiLoc2: def test_is_scalar_access(self): # GH#32085 index with duplicates doesnt matter for _is_scalar_access index = pd.Index([1, 2, 1]) - ser = pd.Series(range(3), index=index) + ser = Series(range(3), index=index) assert ser.iloc._is_scalar_access((1,)) @@ -699,7 +699,7 @@ def test_indexing_zerodim_np_array(self): # GH24919 df = DataFrame([[1, 2], [3, 4]]) result = df.iloc[np.array(0)] - s = pd.Series([1, 2], name=0) + s = Series([1, 2], name=0) tm.assert_series_equal(result, s) def test_series_indexing_zerodim_np_array(self): diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index fd83f9ab29407..b4ea92fae1136 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -329,7 +329,7 @@ def test_dups_fancy_indexing2(self): @pytest.mark.parametrize("case", [lambda s: s, lambda s: s.loc]) def test_duplicate_int_indexing(self, case): # GH 17347 - s = pd.Series(range(3), index=[1, 1, 3]) + s = Series(range(3), index=[1, 1, 3]) expected = s[1] result = case(s)[[1]] tm.assert_series_equal(result, expected) @@ -998,9 +998,7 @@ def test_extension_array_cross_section(): }, index=["a", "b"], ) - expected = pd.Series( - pd.core.arrays.integer_array([1, 3]), index=["A", "B"], name="a" - ) + expected = Series(pd.core.arrays.integer_array([1, 3]), index=["A", "B"], name="a") result = df.loc["a"] tm.assert_series_equal(result, expected) @@ -1014,7 +1012,7 @@ def test_extension_array_cross_section_converts(): {"A": pd.array([1, 2], dtype="Int64"), "B": np.array([1, 2])}, index=["a", "b"] ) result = df.loc["a"] - expected = pd.Series([1, 1], dtype="Int64", index=["A", "B"], name="a") + expected = Series([1, 1], dtype="Int64", index=["A", "B"], name="a") tm.assert_series_equal(result, expected) result = df.iloc[0] @@ -1026,7 +1024,7 @@ def test_extension_array_cross_section_converts(): index=["a", "b"], ) result = df.loc["a"] - expected = pd.Series([1, "a"], dtype=object, index=["A", "B"], name="a") + expected = Series([1, "a"], dtype=object, index=["A", "B"], name="a") tm.assert_series_equal(result, expected) result = df.iloc[0] @@ -1049,7 +1047,7 @@ def test_readonly_indices(): def test_1tuple_without_multiindex(): - ser = pd.Series(range(5)) + ser = Series(range(5)) key = (slice(3),) result = ser[key] @@ -1059,7 +1057,7 @@ def test_1tuple_without_multiindex(): def test_duplicate_index_mistyped_key_raises_keyerror(): # GH#29189 float_index.get_loc(None) should raise KeyError, not TypeError - ser = pd.Series([2, 5, 6, 8], index=[2.0, 4.0, 4.0, 5.0]) + ser = Series([2, 5, 6, 8], index=[2.0, 4.0, 4.0, 5.0]) with pytest.raises(KeyError, match="None"): ser[None] @@ -1072,17 +1070,17 @@ def test_duplicate_index_mistyped_key_raises_keyerror(): def test_setitem_with_bool_mask_and_values_matching_n_trues_in_length(): # GH 30567 - ser = pd.Series([None] * 10) + ser = Series([None] * 10) mask = [False] * 3 + [True] * 5 + [False] * 2 ser[mask] = range(5) result = ser - expected = pd.Series([None] * 3 + list(range(5)) + [None] * 2).astype("object") + expected = Series([None] * 3 + list(range(5)) + [None] * 2).astype("object") tm.assert_series_equal(result, expected) def test_missing_labels_inside_loc_matched_in_error_message(): # GH34272 - s = pd.Series({"a": 1, "b": 2, "c": 3}) + s = Series({"a": 1, "b": 2, "c": 3}) error_message_regex = "missing_0.*missing_1.*missing_2" with pytest.raises(KeyError, match=error_message_regex): s.loc[["a", "b", "missing_0", "c", "missing_1", "missing_2"]] @@ -1092,7 +1090,7 @@ def test_many_missing_labels_inside_loc_error_message_limited(): # GH34272 n = 10000 missing_labels = [f"missing_{label}" for label in range(n)] - s = pd.Series({"a": 1, "b": 2, "c": 3}) + s = Series({"a": 1, "b": 2, "c": 3}) # regex checks labels between 4 and 9995 are replaced with ellipses error_message_regex = "missing_4.*\\.\\.\\..*missing_9995" with pytest.raises(KeyError, match=error_message_regex): @@ -1101,7 +1099,7 @@ def test_many_missing_labels_inside_loc_error_message_limited(): def test_long_text_missing_labels_inside_loc_error_message_limited(): # GH34272 - s = pd.Series({"a": 1, "b": 2, "c": 3}) + s = Series({"a": 1, "b": 2, "c": 3}) missing_labels = [f"long_missing_label_text_{i}" * 5 for i in range(3)] # regex checks for very long labels there are new lines between each error_message_regex = "long_missing_label_text_0.*\\\\n.*long_missing_label_text_1" @@ -1111,7 +1109,7 @@ def test_long_text_missing_labels_inside_loc_error_message_limited(): def test_setitem_categorical(): # https://github.com/pandas-dev/pandas/issues/35369 - df = pd.DataFrame({"h": pd.Series(list("mn")).astype("category")}) + df = pd.DataFrame({"h": Series(list("mn")).astype("category")}) df.h = df.h.cat.reorder_categories(["n", "m"]) expected = pd.DataFrame( {"h": pd.Categorical(["m", "n"]).reorder_categories(["n", "m"])} diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 9b9bca77e17ec..e7f2ad6e8d735 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -737,15 +737,15 @@ def test_setitem_new_key_tz(self): pd.to_datetime(42).tz_localize("UTC"), pd.to_datetime(666).tz_localize("UTC"), ] - expected = pd.Series(vals, index=["foo", "bar"]) + expected = Series(vals, index=["foo", "bar"]) - ser = pd.Series(dtype=object) + ser = Series(dtype=object) ser["foo"] = vals[0] ser["bar"] = vals[1] tm.assert_series_equal(ser, expected) - ser = pd.Series(dtype=object) + ser = Series(dtype=object) ser.loc["foo"] = vals[0] ser.loc["bar"] = vals[1] @@ -907,9 +907,7 @@ def test_loc_copy_vs_view(self): def test_loc_uint64(self): # GH20722 # Test whether loc accept uint64 max value as index. - s = pd.Series( - [1, 2], index=[np.iinfo("uint64").max - 1, np.iinfo("uint64").max] - ) + s = Series([1, 2], index=[np.iinfo("uint64").max - 1, np.iinfo("uint64").max]) result = s.loc[np.iinfo("uint64").max - 1] expected = s.iloc[0] @@ -961,7 +959,7 @@ def test_indexing_zerodim_np_array(self): # GH24924 df = DataFrame([[1, 2], [3, 4]]) result = df.loc[np.array(0)] - s = pd.Series([1, 2], name=0) + s = Series([1, 2], name=0) tm.assert_series_equal(result, s) def test_series_indexing_zerodim_np_array(self): @@ -975,7 +973,7 @@ def test_loc_reverse_assignment(self): data = [1, 2, 3, 4, 5, 6] + [None] * 4 expected = Series(data, index=range(2010, 2020)) - result = pd.Series(index=range(2010, 2020), dtype=np.float64) + result = Series(index=range(2010, 2020), dtype=np.float64) result.loc[2015:2010:-1] = [6, 5, 4, 3, 2, 1] tm.assert_series_equal(result, expected) @@ -1054,7 +1052,7 @@ def test_loc_set_dataframe_multiindex(): def test_loc_mixed_int_float(): # GH#19456 - ser = pd.Series(range(2), pd.Index([1, 2.0], dtype=object)) + ser = Series(range(2), pd.Index([1, 2.0], dtype=object)) result = ser.loc[1] assert result == 0 @@ -1062,12 +1060,12 @@ def test_loc_mixed_int_float(): def test_loc_with_positional_slice_deprecation(): # GH#31840 - ser = pd.Series(range(4), index=["A", "B", "C", "D"]) + ser = Series(range(4), index=["A", "B", "C", "D"]) with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): ser.loc[:3] = 2 - expected = pd.Series([2, 2, 2, 3], index=["A", "B", "C", "D"]) + expected = Series([2, 2, 2, 3], index=["A", "B", "C", "D"]) tm.assert_series_equal(ser, expected) diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index 337ec683ee745..6005f7800178c 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -664,7 +664,7 @@ def test_indexing_timeseries_regression(self): def test_index_name_empty(self): # GH 31368 df = pd.DataFrame({}, index=pd.RangeIndex(0, name="df_index")) - series = pd.Series(1.23, index=pd.RangeIndex(4, name="series_index")) + series = Series(1.23, index=pd.RangeIndex(4, name="series_index")) df["series"] = series expected = pd.DataFrame( @@ -675,7 +675,7 @@ def test_index_name_empty(self): # GH 36527 df = pd.DataFrame() - series = pd.Series(1.23, index=pd.RangeIndex(4, name="series_index")) + series = Series(1.23, index=pd.RangeIndex(4, name="series_index")) df["series"] = series expected = pd.DataFrame( {"series": [1.23] * 4}, index=pd.RangeIndex(4, name="series_index") diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index cd2f5a903d8cc..9a0bfa5c605d9 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -1216,8 +1216,8 @@ def test_validate_ndim(): def test_block_shape(): idx = pd.Index([0, 1, 2, 3, 4]) - a = pd.Series([1, 2, 3]).reindex(idx) - b = pd.Series(pd.Categorical([1, 2, 3])).reindex(idx) + a = Series([1, 2, 3]).reindex(idx) + b = Series(pd.Categorical([1, 2, 3])).reindex(idx) assert a._mgr.blocks[0].mgr_locs.indexer == b._mgr.blocks[0].mgr_locs.indexer @@ -1285,7 +1285,7 @@ def test_interleave_non_unique_cols(): def test_single_block_manager_fastpath_deprecated(): # GH#33092 - ser = pd.Series(range(3)) + ser = Series(range(3)) blk = ser._data.blocks[0] with tm.assert_produces_warning(FutureWarning): SingleBlockManager(blk, ser.index, fastpath=True) diff --git a/pandas/tests/io/excel/test_readers.py b/pandas/tests/io/excel/test_readers.py index 800b4c79b9c09..7c507b0e371e8 100644 --- a/pandas/tests/io/excel/test_readers.py +++ b/pandas/tests/io/excel/test_readers.py @@ -970,7 +970,7 @@ def test_read_excel_squeeze(self, read_ext): f = "test_squeeze" + read_ext actual = pd.read_excel(f, sheet_name="two_columns", index_col=0, squeeze=True) - expected = pd.Series([2, 3, 4], [4, 5, 6], name="b") + expected = Series([2, 3, 4], [4, 5, 6], name="b") expected.index.name = "a" tm.assert_series_equal(actual, expected) @@ -979,7 +979,7 @@ def test_read_excel_squeeze(self, read_ext): tm.assert_frame_equal(actual, expected) actual = pd.read_excel(f, sheet_name="one_column", squeeze=True) - expected = pd.Series([1, 2, 3], name="a") + expected = Series([1, 2, 3], name="a") tm.assert_series_equal(actual, expected) def test_deprecated_kwargs(self, read_ext): diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index dd85db19af959..239bb54f48c16 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2031,9 +2031,9 @@ def test_period(self): def gen_series_formatting(): - s1 = pd.Series(["a"] * 100) - s2 = pd.Series(["ab"] * 100) - s3 = pd.Series(["a", "ab", "abc", "abcd", "abcde", "abcdef"]) + s1 = Series(["a"] * 100) + s2 = Series(["ab"] * 100) + s3 = Series(["a", "ab", "abc", "abcd", "abcde", "abcdef"]) s4 = s3[::-1] test_sers = {"onel": s1, "twol": s2, "asc": s3, "desc": s4} return test_sers @@ -2529,7 +2529,7 @@ def test_max_multi_index_display(self): # Make sure #8532 is fixed def test_consistent_format(self): - s = pd.Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9999, 1, 1] * 10) + s = Series([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9999, 1, 1] * 10) with option_context("display.max_rows", 10, "display.show_dimensions", False): res = repr(s) exp = ( @@ -2618,12 +2618,12 @@ def test_show_dimensions(self): assert "Length" not in repr(s) def test_repr_min_rows(self): - s = pd.Series(range(20)) + s = Series(range(20)) # default setting no truncation even if above min_rows assert ".." not in repr(s) - s = pd.Series(range(61)) + s = Series(range(61)) # default of max_rows 60 triggers truncation if above assert ".." in repr(s) @@ -2671,19 +2671,19 @@ def test_to_string_length(self): assert res == exp def test_to_string_na_rep(self): - s = pd.Series(index=range(100), dtype=np.float64) + s = Series(index=range(100), dtype=np.float64) res = s.to_string(na_rep="foo", max_rows=2) exp = "0 foo\n ..\n99 foo" assert res == exp def test_to_string_float_format(self): - s = pd.Series(range(10), dtype="float64") + s = Series(range(10), dtype="float64") res = s.to_string(float_format=lambda x: f"{x:2.1f}", max_rows=2) exp = "0 0.0\n ..\n9 9.0" assert res == exp def test_to_string_header(self): - s = pd.Series(range(10), dtype="int64") + s = Series(range(10), dtype="int64") s.index.name = "foo" res = s.to_string(header=True, max_rows=2) exp = "foo\n0 0\n ..\n9 9" @@ -2703,7 +2703,7 @@ def test_to_string_multindex_header(self): def test_to_string_empty_col(self): # GH 13653 - s = pd.Series(["", "Hello", "World", "", "", "Mooooo", "", ""]) + s = Series(["", "Hello", "World", "", "", "Mooooo", "", ""]) res = s.to_string(index=False) exp = " \n Hello\n World\n \n \nMooooo\n \n " assert re.match(exp, res) @@ -2760,7 +2760,7 @@ def __getitem__(self, ix): def dtype(self): return DtypeStub() - series = pd.Series(ExtTypeStub()) + series = Series(ExtTypeStub()) res = repr(series) # This line crashed before #33770 was fixed. expected = "0 [False True]\n" + "1 [ True False]\n" + "dtype: DtypeStub" assert res == expected @@ -2787,7 +2787,7 @@ def test_output_display_precision_trailing_zeroes(self): # Happens when display precision is set to zero with pd.option_context("display.precision", 0): - s = pd.Series([840.0, 4200.0]) + s = Series([840.0, 4200.0]) expected_output = "0 840\n1 4200\ndtype: float64" assert str(s) == expected_output diff --git a/pandas/tests/io/formats/test_to_latex.py b/pandas/tests/io/formats/test_to_latex.py index 908fdea2f73d0..b2edb5309f299 100644 --- a/pandas/tests/io/formats/test_to_latex.py +++ b/pandas/tests/io/formats/test_to_latex.py @@ -979,11 +979,11 @@ def multiindex_frame(self): """Multiindex dataframe for testing multirow LaTeX macros.""" yield DataFrame.from_dict( { - ("c1", 0): pd.Series({x: x for x in range(4)}), - ("c1", 1): pd.Series({x: x + 4 for x in range(4)}), - ("c2", 0): pd.Series({x: x for x in range(4)}), - ("c2", 1): pd.Series({x: x + 4 for x in range(4)}), - ("c3", 0): pd.Series({x: x for x in range(4)}), + ("c1", 0): Series({x: x for x in range(4)}), + ("c1", 1): Series({x: x + 4 for x in range(4)}), + ("c2", 0): Series({x: x for x in range(4)}), + ("c2", 1): Series({x: x + 4 for x in range(4)}), + ("c3", 0): Series({x: x for x in range(4)}), } ).T diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index e12424888f4af..4d8d4ecb50a5a 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -796,7 +796,7 @@ def test_date_index_and_values(self, date_format, as_object, date_typ): if as_object: data.append("a") - ser = pd.Series(data, index=data) + ser = Series(data, index=data) result = ser.to_json(date_format=date_format) if date_format == "epoch": @@ -1042,7 +1042,7 @@ def test_timedelta_to_json(self, as_object, date_format, timedelta_typ): if as_object: data.append("a") - ser = pd.Series(data, index=data) + ser = Series(data, index=data) if date_format == "iso": expected = ( '{"P1DT0H0M0S":"P1DT0H0M0S","P2DT0H0M0S":"P2DT0H0M0S","null":null}' @@ -1150,7 +1150,7 @@ def test_sparse(self): expected = df.to_json() assert expected == sdf.to_json() - s = pd.Series(np.random.randn(10)) + s = Series(np.random.randn(10)) s.loc[:8] = np.nan ss = s.astype("Sparse") @@ -1730,5 +1730,5 @@ def test_json_pandas_nulls(self, nulls_fixture): def test_readjson_bool_series(self): # GH31464 result = read_json("[true, true, false]", typ="series") - expected = pd.Series([True, True, False]) + expected = Series([True, True, False]) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 42614f1eee8af..7eeba97b799ae 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -661,7 +661,7 @@ def test_walk(self, where, expected, setup_path): "df2": pd.DataFrame([4, 5, 6]), "df3": pd.DataFrame([6, 7, 8]), "df4": pd.DataFrame([9, 10, 11]), - "s1": pd.Series([10, 9, 8]), + "s1": Series([10, 9, 8]), # Next 3 items aren't pandas objects and should be ignored "a1": np.array([[1, 2, 3], [4, 5, 6]]), "tb1": np.array([(1, 2, 3), (4, 5, 6)], dtype="i,i,i"), @@ -1113,7 +1113,7 @@ def test_latin_encoding(self, setup_path, dtype, val): key = "data" val = [x.decode(enc) if isinstance(x, bytes) else x for x in val] - ser = pd.Series(val, dtype=dtype) + ser = Series(val, dtype=dtype) with ensure_clean_path(setup_path) as store: ser.to_hdf(store, key, format="table", encoding=enc, nan_rep=nan_rep) @@ -1509,7 +1509,7 @@ def test_to_hdf_with_min_itemsize(self, setup_path): def test_to_hdf_errors(self, format, setup_path): data = ["\ud800foo"] - ser = pd.Series(data, index=pd.Index(data)) + ser = Series(data, index=pd.Index(data)) with ensure_clean_path(setup_path) as path: # GH 20835 ser.to_hdf(path, "table", format=format, errors="surrogatepass") @@ -4502,7 +4502,7 @@ def test_categorical_nan_only_columns(self, setup_path): "a": ["a", "b", "c", np.nan], "b": [np.nan, np.nan, np.nan, np.nan], "c": [1, 2, 3, 4], - "d": pd.Series([None] * 4, dtype=object), + "d": Series([None] * 4, dtype=object), } ) df["a"] = df.a.astype("category") diff --git a/pandas/tests/io/test_stata.py b/pandas/tests/io/test_stata.py index 88f61390957a6..30926b2bd0241 100644 --- a/pandas/tests/io/test_stata.py +++ b/pandas/tests/io/test_stata.py @@ -1059,7 +1059,7 @@ def test_categorical_order(self, file): (col, pd.Categorical.from_codes(codes, labels, ordered=True)) ) else: - cols.append((col, pd.Series(labels, dtype=np.float32))) + cols.append((col, Series(labels, dtype=np.float32))) expected = DataFrame.from_dict(dict(cols)) # Read with and with out categoricals, ensure order is identical @@ -1089,7 +1089,7 @@ def test_categorical_sorting(self, file): cat = pd.Categorical.from_codes( codes=codes, categories=categories, ordered=True ) - expected = pd.Series(cat, name="srh") + expected = Series(cat, name="srh") tm.assert_series_equal(expected, parsed["srh"]) @pytest.mark.parametrize("file", ["dta19_115", "dta19_117"]) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index d56c882471a9a..271cf65433afe 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -901,7 +901,7 @@ def test_xticklabels(self): def test_xtick_barPlot(self): # GH28172 - s = pd.Series(range(10), index=[f"P{i:02d}" for i in range(10)]) + s = Series(range(10), index=[f"P{i:02d}" for i in range(10)]) ax = s.plot.bar(xticks=range(0, 11, 2)) exp = np.array(list(range(0, 11, 2))) tm.assert_numpy_array_equal(exp, ax.get_xticks()) @@ -947,7 +947,7 @@ def test_plot_xlim_for_series(self, kind): def test_plot_no_rows(self): # GH 27758 - df = pd.Series(dtype=int) + df = Series(dtype=int) assert df.empty ax = df.plot() assert len(ax.get_lines()) == 1 @@ -956,12 +956,12 @@ def test_plot_no_rows(self): assert len(line.get_ydata()) == 0 def test_plot_no_numeric_data(self): - df = pd.Series(["a", "b", "c"]) + df = Series(["a", "b", "c"]) with pytest.raises(TypeError): df.plot() def test_style_single_ok(self): - s = pd.Series([1, 2]) + s = Series([1, 2]) ax = s.plot(style="s", color="C3") assert ax.lines[0].get_color() == "C3" @@ -972,7 +972,7 @@ def test_style_single_ok(self): @pytest.mark.parametrize("kind", ["line", "area", "bar"]) def test_xlabel_ylabel_series(self, kind, index_name, old_label, new_label): # GH 9093 - ser = pd.Series([1, 2, 3, 4]) + ser = Series([1, 2, 3, 4]) ser.index.name = index_name # default is the ylabel is not shown and xlabel is index name diff --git a/pandas/tests/reductions/test_reductions.py b/pandas/tests/reductions/test_reductions.py index fe97925c2bb74..02231f0431d9f 100644 --- a/pandas/tests/reductions/test_reductions.py +++ b/pandas/tests/reductions/test_reductions.py @@ -643,40 +643,40 @@ def test_empty(self, method, unit, use_bottleneck, dtype): df = DataFrame(np.empty((10, 0)), dtype=dtype) assert (getattr(df, method)(1) == unit).all() - s = pd.Series([1], dtype=dtype) + s = Series([1], dtype=dtype) result = getattr(s, method)(min_count=2) assert pd.isna(result) result = getattr(s, method)(skipna=False, min_count=2) assert pd.isna(result) - s = pd.Series([np.nan], dtype=dtype) + s = Series([np.nan], dtype=dtype) result = getattr(s, method)(min_count=2) assert pd.isna(result) - s = pd.Series([np.nan, 1], dtype=dtype) + s = Series([np.nan, 1], dtype=dtype) result = getattr(s, method)(min_count=2) assert pd.isna(result) @pytest.mark.parametrize("method, unit", [("sum", 0.0), ("prod", 1.0)]) def test_empty_multi(self, method, unit): - s = pd.Series( + s = Series( [1, np.nan, np.nan, np.nan], index=pd.MultiIndex.from_product([("a", "b"), (0, 1)]), ) # 1 / 0 by default result = getattr(s, method)(level=0) - expected = pd.Series([1, unit], index=["a", "b"]) + expected = Series([1, unit], index=["a", "b"]) tm.assert_series_equal(result, expected) # min_count=0 result = getattr(s, method)(level=0, min_count=0) - expected = pd.Series([1, unit], index=["a", "b"]) + expected = Series([1, unit], index=["a", "b"]) tm.assert_series_equal(result, expected) # min_count=1 result = getattr(s, method)(level=0, min_count=1) - expected = pd.Series([1, np.nan], index=["a", "b"]) + expected = Series([1, np.nan], index=["a", "b"]) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("method", ["mean", "median", "std", "var"]) @@ -844,13 +844,13 @@ def test_idxmax(self): # Float64Index # GH#5914 - s = pd.Series([1, 2, 3], [1.1, 2.1, 3.1]) + s = Series([1, 2, 3], [1.1, 2.1, 3.1]) result = s.idxmax() assert result == 3.1 result = s.idxmin() assert result == 1.1 - s = pd.Series(s.index, s.index) + s = Series(s.index, s.index) result = s.idxmax() assert result == 3.1 result = s.idxmin() @@ -876,7 +876,7 @@ def test_all_any_params(self): assert not s2.any(skipna=True) # Check level. - s = pd.Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) + s = Series([False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2]) tm.assert_series_equal(s.all(level=0), Series([False, True, False])) tm.assert_series_equal(s.any(level=0), Series([False, True, True])) @@ -908,7 +908,7 @@ def test_all_any_boolean(self): assert not s4.any(skipna=False) # Check level TODO(GH-33449) result should also be boolean - s = pd.Series( + s = Series( [False, False, True, True, False, True], index=[0, 0, 1, 1, 2, 2], dtype="boolean", @@ -920,7 +920,7 @@ def test_any_axis1_bool_only(self): # GH#32432 df = pd.DataFrame({"A": [True, False], "B": [1, 2]}) result = df.any(axis=1, bool_only=True) - expected = pd.Series([True, False]) + expected = Series([True, False]) tm.assert_series_equal(result, expected) def test_timedelta64_analytics(self): @@ -968,12 +968,12 @@ def test_timedelta64_analytics(self): @pytest.mark.parametrize( "test_input,error_type", [ - (pd.Series([], dtype="float64"), ValueError), + (Series([], dtype="float64"), ValueError), # For strings, or any Series with dtype 'O' - (pd.Series(["foo", "bar", "baz"]), TypeError), - (pd.Series([(1,), (2,)]), TypeError), + (Series(["foo", "bar", "baz"]), TypeError), + (Series([(1,), (2,)]), TypeError), # For mixed data types - (pd.Series(["foo", "foo", "bar", "bar", None, np.nan, "baz"]), TypeError), + (Series(["foo", "foo", "bar", "bar", None, np.nan, "baz"]), TypeError), ], ) def test_assert_idxminmax_raises(self, test_input, error_type): @@ -991,7 +991,7 @@ def test_assert_idxminmax_raises(self, test_input, error_type): def test_idxminmax_with_inf(self): # For numeric data with NA and Inf (GH #13595) - s = pd.Series([0, -np.inf, np.inf, np.nan]) + s = Series([0, -np.inf, np.inf, np.nan]) assert s.idxmin() == 1 assert np.isnan(s.idxmin(skipna=False)) diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index 28d33ebb23c20..1b9145679fb12 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -120,7 +120,7 @@ def test_resample_count_empty_series(freq, empty_series_dti, resample_method): index = _asfreq_compat(empty_series_dti.index, freq) - expected = pd.Series([], dtype="int64", index=index, name=empty_series_dti.name) + expected = Series([], dtype="int64", index=index, name=empty_series_dti.name) tm.assert_series_equal(result, expected) @@ -174,7 +174,7 @@ def test_resample_size_empty_dataframe(freq, empty_frame_dti): index = _asfreq_compat(empty_frame_dti.index, freq) - expected = pd.Series([], dtype="int64", index=index) + expected = Series([], dtype="int64", index=index) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 9475dcc6981ff..07e47650d0c24 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -111,7 +111,7 @@ def test_resample_basic(series, closed, expected): def test_resample_integerarray(): # GH 25580, resample on IntegerArray - ts = pd.Series( + ts = Series( range(9), index=pd.date_range("1/1/2000", periods=9, freq="T"), dtype="Int64" ) result = ts.resample("3T").sum() @@ -849,7 +849,7 @@ def test_resample_origin_epoch_with_tz_day_vs_24h(): start, end = "2000-10-01 23:30:00+0500", "2000-12-02 00:30:00+0500" rng = pd.date_range(start, end, freq="7min") random_values = np.random.randn(len(rng)) - ts_1 = pd.Series(random_values, index=rng) + ts_1 = Series(random_values, index=rng) result_1 = ts_1.resample("D", origin="epoch").mean() result_2 = ts_1.resample("24H", origin="epoch").mean() @@ -865,7 +865,7 @@ def test_resample_origin_epoch_with_tz_day_vs_24h(): # check that we have the similar results with two different timezones (+2H and +5H) start, end = "2000-10-01 23:30:00+0200", "2000-12-02 00:30:00+0200" rng = pd.date_range(start, end, freq="7min") - ts_2 = pd.Series(random_values, index=rng) + ts_2 = Series(random_values, index=rng) result_5 = ts_2.resample("D", origin="epoch").mean() result_6 = ts_2.resample("24H", origin="epoch").mean() tm.assert_series_equal(result_1.tz_localize(None), result_5.tz_localize(None)) @@ -877,7 +877,7 @@ def test_resample_origin_with_day_freq_on_dst(): tz = "America/Chicago" def _create_series(values, timestamps, freq="D"): - return pd.Series( + return Series( values, index=pd.DatetimeIndex( [Timestamp(t, tz=tz) for t in timestamps], freq=freq, ambiguous=True @@ -888,7 +888,7 @@ def _create_series(values, timestamps, freq="D"): start = pd.Timestamp("2013-11-02", tz=tz) end = pd.Timestamp("2013-11-03 23:59", tz=tz) rng = pd.date_range(start, end, freq="1h") - ts = pd.Series(np.ones(len(rng)), index=rng) + ts = Series(np.ones(len(rng)), index=rng) expected = _create_series([24.0, 25.0], ["2013-11-02", "2013-11-03"]) for origin in ["epoch", "start", "start_day", start, None]: @@ -899,7 +899,7 @@ def _create_series(values, timestamps, freq="D"): start = pd.Timestamp("2013-11-03", tz=tz) end = pd.Timestamp("2013-11-03 23:59", tz=tz) rng = pd.date_range(start, end, freq="1h") - ts = pd.Series(np.ones(len(rng)), index=rng) + ts = Series(np.ones(len(rng)), index=rng) expected_ts = ["2013-11-02 22:00-05:00", "2013-11-03 22:00-06:00"] expected = _create_series([23.0, 2.0], expected_ts) @@ -1689,9 +1689,7 @@ def test_resample_equivalent_offsets(n1, freq1, n2, freq2, k): # GH 24127 n1_ = n1 * k n2_ = n2 * k - s = pd.Series( - 0, index=pd.date_range("19910905 13:00", "19911005 07:00", freq=freq1) - ) + s = Series(0, index=pd.date_range("19910905 13:00", "19911005 07:00", freq=freq1)) s = s + range(len(s)) result1 = s.resample(str(n1_) + freq1).mean() @@ -1781,9 +1779,9 @@ def test_resample_calendar_day_with_dst( first: str, last: str, freq_in: str, freq_out: str, exp_last: str ): # GH 35219 - ts = pd.Series(1.0, pd.date_range(first, last, freq=freq_in, tz="Europe/Amsterdam")) + ts = Series(1.0, pd.date_range(first, last, freq=freq_in, tz="Europe/Amsterdam")) result = ts.resample(freq_out).pad() - expected = pd.Series( + expected = Series( 1.0, pd.date_range(first, exp_last, freq=freq_out, tz="Europe/Amsterdam") ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 8b3adbf08d157..24695a38a85ac 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -226,7 +226,7 @@ def test_loffset_returns_datetimeindex(frame, kind, agg_arg): ) def test_resample_with_non_zero_base(start, end, start_freq, end_freq, base, offset): # GH 23882 - s = pd.Series(0, index=pd.period_range(start, end, freq=start_freq)) + s = Series(0, index=pd.period_range(start, end, freq=start_freq)) s = s + np.arange(len(s)) with tm.assert_produces_warning(FutureWarning): result = s.resample(end_freq, base=base).mean() diff --git a/pandas/tests/resample/test_period_index.py b/pandas/tests/resample/test_period_index.py index fe02eaef8ba82..f5b655ebd416b 100644 --- a/pandas/tests/resample/test_period_index.py +++ b/pandas/tests/resample/test_period_index.py @@ -816,7 +816,7 @@ def test_resample_with_only_nat(self): ) def test_resample_with_offset(self, start, end, start_freq, end_freq, offset): # GH 23882 & 31809 - s = pd.Series(0, index=pd.period_range(start, end, freq=start_freq)) + s = Series(0, index=pd.period_range(start, end, freq=start_freq)) s = s + np.arange(len(s)) result = s.resample(end_freq, offset=offset).mean() result = result.to_timestamp(end_freq) @@ -861,9 +861,9 @@ def test_sum_min_count(self): index = pd.date_range(start="2018", freq="M", periods=6) data = np.ones(6) data[3:6] = np.nan - s = pd.Series(data, index).to_period() + s = Series(data, index).to_period() result = s.resample("Q").sum(min_count=1) - expected = pd.Series( + expected = Series( [3.0, np.nan], index=PeriodIndex(["2018Q1", "2018Q2"], freq="Q-DEC") ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index e4af5d93ff771..dbb85c2f890bf 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -595,10 +595,10 @@ def test_resample_agg_readonly(): arr = np.zeros_like(index) arr.setflags(write=False) - ser = pd.Series(arr, index=index) + ser = Series(arr, index=index) rs = ser.resample("1D") - expected = pd.Series([pd.Timestamp(0), pd.Timestamp(0)], index=index[::24]) + expected = Series([pd.Timestamp(0), pd.Timestamp(0)], index=index[::24]) result = rs.agg("last") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 2f22be7c8cce9..53966392d3aff 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -142,7 +142,7 @@ def test_groupby_with_origin(): middle = "1/15/2000 00:00:00" rng = pd.date_range(start, end, freq="1231min") # prime number - ts = pd.Series(np.random.randn(len(rng)), index=rng) + ts = Series(np.random.randn(len(rng)), index=rng) ts2 = ts[middle:end] # proves that grouper without a fixed origin does not work @@ -356,7 +356,7 @@ def test_apply_to_one_column_of_df(): index=pd.date_range("2012-01-01", periods=10, freq="20min"), ) result = df.resample("H").apply(lambda group: group.col.sum()) - expected = pd.Series( + expected = Series( [3, 12, 21, 9], index=pd.date_range("2012-01-01", periods=4, freq="H") ) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index f638706207679..c8c5fa47706fc 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -167,9 +167,9 @@ def test_aggregate_normal(resample_method): ], ) def test_resample_entirely_nat_window(method, method_args, unit): - s = pd.Series([0] * 2 + [np.nan] * 2, index=pd.date_range("2017", periods=4)) + s = Series([0] * 2 + [np.nan] * 2, index=pd.date_range("2017", periods=4)) result = methodcaller(method, **method_args)(s.resample("2d")) - expected = pd.Series( + expected = Series( [0.0, unit], index=pd.DatetimeIndex(["2017-01-01", "2017-01-03"], freq="2D") ) tm.assert_series_equal(result, expected) @@ -278,14 +278,14 @@ def test_repr(): ], ) def test_upsample_sum(method, method_args, expected_values): - s = pd.Series(1, index=pd.date_range("2017", periods=2, freq="H")) + s = Series(1, index=pd.date_range("2017", periods=2, freq="H")) resampled = s.resample("30T") index = pd.DatetimeIndex( ["2017-01-01T00:00:00", "2017-01-01T00:30:00", "2017-01-01T01:00:00"], freq="30T", ) result = methodcaller(method, **method_args)(resampled) - expected = pd.Series(expected_values, index=index) + expected = Series(expected_values, index=index) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/resample/test_timedelta.py b/pandas/tests/resample/test_timedelta.py index 3fa85e62d028c..d0a0cf3cacd16 100644 --- a/pandas/tests/resample/test_timedelta.py +++ b/pandas/tests/resample/test_timedelta.py @@ -144,7 +144,7 @@ def test_resample_timedelta_edge_case(start, end, freq, resample_freq): # GH 33498 # check that the timedelta bins does not contains an extra bin idx = pd.timedelta_range(start=start, end=end, freq=freq) - s = pd.Series(np.arange(len(idx)), index=idx) + s = Series(np.arange(len(idx)), index=idx) result = s.resample(resample_freq).min() expected_index = pd.timedelta_range(freq=resample_freq, start=start, end=end) tm.assert_index_equal(result.index, expected_index) diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index d4d4c4190417e..4cc72e66353b3 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -762,7 +762,7 @@ def test_join_on_tz_aware_datetimeindex(self): ) result = df1.join(df2.set_index("date"), on="date") expected = df1.copy() - expected["vals_2"] = pd.Series([np.nan] * 2 + list("tuv"), dtype=object) + expected["vals_2"] = Series([np.nan] * 2 + list("tuv"), dtype=object) tm.assert_frame_equal(result, expected) def test_join_datetime_string(self): diff --git a/pandas/tests/reshape/merge/test_merge.py b/pandas/tests/reshape/merge/test_merge.py index aee503235d36c..6968dc781b6e3 100644 --- a/pandas/tests/reshape/merge/test_merge.py +++ b/pandas/tests/reshape/merge/test_merge.py @@ -46,22 +46,22 @@ def get_test_data(ngroups=NGROUPS, n=N): def get_series(): return [ - pd.Series([1], dtype="int64"), - pd.Series([1], dtype="Int64"), - pd.Series([1.23]), - pd.Series(["foo"]), - pd.Series([True]), - pd.Series([pd.Timestamp("2018-01-01")]), - pd.Series([pd.Timestamp("2018-01-01", tz="US/Eastern")]), + Series([1], dtype="int64"), + Series([1], dtype="Int64"), + Series([1.23]), + Series(["foo"]), + Series([True]), + Series([pd.Timestamp("2018-01-01")]), + Series([pd.Timestamp("2018-01-01", tz="US/Eastern")]), ] def get_series_na(): return [ - pd.Series([np.nan], dtype="Int64"), - pd.Series([np.nan], dtype="float"), - pd.Series([np.nan], dtype="object"), - pd.Series([pd.NaT]), + Series([np.nan], dtype="Int64"), + Series([np.nan], dtype="float"), + Series([np.nan], dtype="object"), + Series([pd.NaT]), ] @@ -253,16 +253,16 @@ def test_merge_different_column_key_names(self): right, left_on="lkey", right_on="rkey", how="outer", sort=True ) - exp = pd.Series(["bar", "baz", "foo", "foo", "foo", "foo", np.nan], name="lkey") + exp = Series(["bar", "baz", "foo", "foo", "foo", "foo", np.nan], name="lkey") tm.assert_series_equal(merged["lkey"], exp) - exp = pd.Series(["bar", np.nan, "foo", "foo", "foo", "foo", "qux"], name="rkey") + exp = Series(["bar", np.nan, "foo", "foo", "foo", "foo", "qux"], name="rkey") tm.assert_series_equal(merged["rkey"], exp) - exp = pd.Series([2, 3, 1, 1, 4, 4, np.nan], name="value_x") + exp = Series([2, 3, 1, 1, 4, 4, np.nan], name="value_x") tm.assert_series_equal(merged["value_x"], exp) - exp = pd.Series([6, np.nan, 5, 8, 5, 8, 7], name="value_y") + exp = Series([6, np.nan, 5, 8, 5, 8, 7], name="value_y") tm.assert_series_equal(merged["value_y"], exp) def test_merge_copy(self): @@ -541,9 +541,9 @@ def test_merge_empty_frame(self, series_of_dtype, series_of_dtype2): df_empty = df[:0] expected = pd.DataFrame( { - "value_x": pd.Series(dtype=df.dtypes["value"]), - "key": pd.Series(dtype=df.dtypes["key"]), - "value_y": pd.Series(dtype=df.dtypes["value"]), + "value_x": Series(dtype=df.dtypes["value"]), + "key": Series(dtype=df.dtypes["key"]), + "value_y": Series(dtype=df.dtypes["value"]), }, columns=["value_x", "key", "value_y"], ) @@ -676,7 +676,7 @@ def test_join_append_timedeltas(self): def test_other_datetime_unit(self): # GH 13389 df1 = pd.DataFrame({"entity_id": [101, 102]}) - s = pd.Series([None, None], index=[101, 102], name="days") + s = Series([None, None], index=[101, 102], name="days") for dtype in [ "datetime64[D]", @@ -707,7 +707,7 @@ def test_other_datetime_unit(self): def test_other_timedelta_unit(self, unit): # GH 13389 df1 = pd.DataFrame({"entity_id": [101, 102]}) - s = pd.Series([None, None], index=[101, 102], name="days") + s = Series([None, None], index=[101, 102], name="days") dtype = f"m8[{unit}]" df2 = s.astype(dtype).to_frame("days") @@ -812,11 +812,11 @@ def test_merge_on_datetime64tz_empty(self): result = left.merge(right, on="date") expected = pd.DataFrame( { - "value_x": pd.Series(dtype=float), - "date2_x": pd.Series(dtype=dtz), - "date": pd.Series(dtype=dtz), - "value_y": pd.Series(dtype=float), - "date2_y": pd.Series(dtype=dtz), + "value_x": Series(dtype=float), + "date2_x": Series(dtype=dtz), + "date": Series(dtype=dtz), + "value_y": Series(dtype=float), + "date2_y": Series(dtype=dtz), }, columns=["value_x", "date2_x", "date", "value_y", "date2_y"], ) @@ -1521,8 +1521,8 @@ def test_merge_incompat_infer_boolean_object(self): ([0, 1, 2], Series(["a", "b", "a"]).astype("category")), ([0.0, 1.0, 2.0], Series(["a", "b", "a"]).astype("category")), # no not infer - ([0, 1], pd.Series([False, True], dtype=object)), - ([0, 1], pd.Series([False, True], dtype=bool)), + ([0, 1], Series([False, True], dtype=object)), + ([0, 1], Series([False, True], dtype=bool)), ], ) def test_merge_incompat_dtypes_are_ok(self, df1_vals, df2_vals): @@ -1836,10 +1836,10 @@ def test_merging_with_bool_or_int_cateorical_column( def test_merge_on_int_array(self): # GH 23020 - df = pd.DataFrame({"A": pd.Series([1, 2, np.nan], dtype="Int64"), "B": 1}) + df = pd.DataFrame({"A": Series([1, 2, np.nan], dtype="Int64"), "B": 1}) result = pd.merge(df, df, on="A") expected = pd.DataFrame( - {"A": pd.Series([1, 2, np.nan], dtype="Int64"), "B_x": 1, "B_y": 1} + {"A": Series([1, 2, np.nan], dtype="Int64"), "B_x": 1, "B_y": 1} ) tm.assert_frame_equal(result, expected) @@ -1956,7 +1956,7 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm): [["a", "b"], [0, 1]], names=["outer", "inner"] ), ) - b = pd.Series( + b = Series( [1, 2, 3, 4], index=pd.MultiIndex.from_product( [["a", "b"], [1, 2]], names=["outer", "inner"] diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index 48500531aa351..340b50ed60ceb 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -91,7 +91,7 @@ def _check_expected_dtype(self, obj, label): assert obj.dtype == "object" else: assert obj.dtype == label - elif isinstance(obj, pd.Series): + elif isinstance(obj, Series): if label.startswith("period"): assert obj.dtype == "Period[M]" else: @@ -103,7 +103,7 @@ def test_dtypes(self): # to confirm test case covers intended dtypes for typ, vals in self.data.items(): self._check_expected_dtype(pd.Index(vals), typ) - self._check_expected_dtype(pd.Series(vals), typ) + self._check_expected_dtype(Series(vals), typ) def test_concatlike_same_dtypes(self): # GH 13660 @@ -155,42 +155,42 @@ def test_concatlike_same_dtypes(self): # ----- Series ----- # # series.append - res = pd.Series(vals1).append(pd.Series(vals2), ignore_index=True) - exp = pd.Series(exp_data) + res = Series(vals1).append(Series(vals2), ignore_index=True) + exp = Series(exp_data) tm.assert_series_equal(res, exp, check_index_type=True) # concat - res = pd.concat([pd.Series(vals1), pd.Series(vals2)], ignore_index=True) + res = pd.concat([Series(vals1), Series(vals2)], ignore_index=True) tm.assert_series_equal(res, exp, check_index_type=True) # 3 elements - res = pd.Series(vals1).append( - [pd.Series(vals2), pd.Series(vals3)], ignore_index=True + res = Series(vals1).append( + [Series(vals2), Series(vals3)], ignore_index=True ) - exp = pd.Series(exp_data3) + exp = Series(exp_data3) tm.assert_series_equal(res, exp) res = pd.concat( - [pd.Series(vals1), pd.Series(vals2), pd.Series(vals3)], + [Series(vals1), Series(vals2), Series(vals3)], ignore_index=True, ) tm.assert_series_equal(res, exp) # name mismatch - s1 = pd.Series(vals1, name="x") - s2 = pd.Series(vals2, name="y") + s1 = Series(vals1, name="x") + s2 = Series(vals2, name="y") res = s1.append(s2, ignore_index=True) - exp = pd.Series(exp_data) + exp = Series(exp_data) tm.assert_series_equal(res, exp, check_index_type=True) res = pd.concat([s1, s2], ignore_index=True) tm.assert_series_equal(res, exp, check_index_type=True) # name match - s1 = pd.Series(vals1, name="x") - s2 = pd.Series(vals2, name="x") + s1 = Series(vals1, name="x") + s2 = Series(vals2, name="x") res = s1.append(s2, ignore_index=True) - exp = pd.Series(exp_data, name="x") + exp = Series(exp_data, name="x") tm.assert_series_equal(res, exp, check_index_type=True) res = pd.concat([s1, s2], ignore_index=True) @@ -202,16 +202,16 @@ def test_concatlike_same_dtypes(self): "only Series and DataFrame objs are valid" ) with pytest.raises(TypeError, match=msg): - pd.Series(vals1).append(vals2) + Series(vals1).append(vals2) with pytest.raises(TypeError, match=msg): - pd.Series(vals1).append([pd.Series(vals2), vals3]) + Series(vals1).append([Series(vals2), vals3]) with pytest.raises(TypeError, match=msg): - pd.concat([pd.Series(vals1), vals2]) + pd.concat([Series(vals1), vals2]) with pytest.raises(TypeError, match=msg): - pd.concat([pd.Series(vals1), pd.Series(vals2), vals3]) + pd.concat([Series(vals1), Series(vals2), vals3]) def test_concatlike_dtypes_coercion(self): # GH 13660 @@ -265,23 +265,23 @@ def test_concatlike_dtypes_coercion(self): # ----- Series ----- # # series.append - res = pd.Series(vals1).append(pd.Series(vals2), ignore_index=True) - exp = pd.Series(exp_data, dtype=exp_series_dtype) + res = Series(vals1).append(Series(vals2), ignore_index=True) + exp = Series(exp_data, dtype=exp_series_dtype) tm.assert_series_equal(res, exp, check_index_type=True) # concat - res = pd.concat([pd.Series(vals1), pd.Series(vals2)], ignore_index=True) + res = pd.concat([Series(vals1), Series(vals2)], ignore_index=True) tm.assert_series_equal(res, exp, check_index_type=True) # 3 elements - res = pd.Series(vals1).append( - [pd.Series(vals2), pd.Series(vals3)], ignore_index=True + res = Series(vals1).append( + [Series(vals2), Series(vals3)], ignore_index=True ) - exp = pd.Series(exp_data3, dtype=exp_series_dtype) + exp = Series(exp_data3, dtype=exp_series_dtype) tm.assert_series_equal(res, exp) res = pd.concat( - [pd.Series(vals1), pd.Series(vals2), pd.Series(vals3)], + [Series(vals1), Series(vals2), Series(vals3)], ignore_index=True, ) tm.assert_series_equal(res, exp) @@ -306,15 +306,15 @@ def test_concatlike_common_coerce_to_pandas_object(self): assert isinstance(res[0], pd.Timestamp) assert isinstance(res[-1], pd.Timedelta) - dts = pd.Series(dti) - tds = pd.Series(tdi) + dts = Series(dti) + tds = Series(tdi) res = dts.append(tds) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) assert isinstance(res.iloc[0], pd.Timestamp) assert isinstance(res.iloc[-1], pd.Timedelta) res = pd.concat([dts, tds]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) assert isinstance(res.iloc[0], pd.Timestamp) assert isinstance(res.iloc[-1], pd.Timedelta) @@ -331,13 +331,13 @@ def test_concatlike_datetimetz(self, tz_aware_fixture): res = dti1.append(dti2) tm.assert_index_equal(res, exp) - dts1 = pd.Series(dti1) - dts2 = pd.Series(dti2) + dts1 = Series(dti1) + dts2 = Series(dti2) res = dts1.append(dts2) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts2]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) @pytest.mark.parametrize("tz", ["UTC", "US/Eastern", "Asia/Tokyo", "EST5EDT"]) def test_concatlike_datetimetz_short(self, tz): @@ -377,13 +377,13 @@ def test_concatlike_datetimetz_to_object(self, tz_aware_fixture): res = dti1.append(dti2) tm.assert_index_equal(res, exp) - dts1 = pd.Series(dti1) - dts2 = pd.Series(dti2) + dts1 = Series(dti1) + dts2 = Series(dti2) res = dts1.append(dts2) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts2]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) # different tz dti3 = pd.DatetimeIndex(["2012-01-01", "2012-01-02"], tz="US/Pacific") @@ -401,13 +401,13 @@ def test_concatlike_datetimetz_to_object(self, tz_aware_fixture): res = dti1.append(dti3) # tm.assert_index_equal(res, exp) - dts1 = pd.Series(dti1) - dts3 = pd.Series(dti3) + dts1 = Series(dti1) + dts3 = Series(dti3) res = dts1.append(dts3) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([dts1, dts3]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) def test_concatlike_common_period(self): # GH 13660 @@ -419,13 +419,13 @@ def test_concatlike_common_period(self): res = pi1.append(pi2) tm.assert_index_equal(res, exp) - ps1 = pd.Series(pi1) - ps2 = pd.Series(pi2) + ps1 = Series(pi1) + ps2 = Series(pi2) res = ps1.append(ps2) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, ps2]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) def test_concatlike_common_period_diff_freq_to_object(self): # GH 13221 @@ -445,13 +445,13 @@ def test_concatlike_common_period_diff_freq_to_object(self): res = pi1.append(pi2) tm.assert_index_equal(res, exp) - ps1 = pd.Series(pi1) - ps2 = pd.Series(pi2) + ps1 = Series(pi1) + ps2 = Series(pi2) res = ps1.append(ps2) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, ps2]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) def test_concatlike_common_period_mixed_dt_to_object(self): # GH 13221 @@ -471,13 +471,13 @@ def test_concatlike_common_period_mixed_dt_to_object(self): res = pi1.append(tdi) tm.assert_index_equal(res, exp) - ps1 = pd.Series(pi1) - tds = pd.Series(tdi) + ps1 = Series(pi1) + tds = Series(tdi) res = ps1.append(tds) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([ps1, tds]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) # inverse exp = pd.Index( @@ -493,47 +493,47 @@ def test_concatlike_common_period_mixed_dt_to_object(self): res = tdi.append(pi1) tm.assert_index_equal(res, exp) - ps1 = pd.Series(pi1) - tds = pd.Series(tdi) + ps1 = Series(pi1) + tds = Series(tdi) res = tds.append(ps1) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) res = pd.concat([tds, ps1]) - tm.assert_series_equal(res, pd.Series(exp, index=[0, 1, 0, 1])) + tm.assert_series_equal(res, Series(exp, index=[0, 1, 0, 1])) def test_concat_categorical(self): # GH 13524 # same categories -> category - s1 = pd.Series([1, 2, np.nan], dtype="category") - s2 = pd.Series([2, 1, 2], dtype="category") + s1 = Series([1, 2, np.nan], dtype="category") + s2 = Series([2, 1, 2], dtype="category") - exp = pd.Series([1, 2, np.nan, 2, 1, 2], dtype="category") + exp = Series([1, 2, np.nan, 2, 1, 2], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) # partially different categories => not-category - s1 = pd.Series([3, 2], dtype="category") - s2 = pd.Series([2, 1], dtype="category") + s1 = Series([3, 2], dtype="category") + s2 = Series([2, 1], dtype="category") - exp = pd.Series([3, 2, 2, 1]) + exp = Series([3, 2, 2, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) # completely different categories (same dtype) => not-category - s1 = pd.Series([10, 11, np.nan], dtype="category") - s2 = pd.Series([np.nan, 1, 3, 2], dtype="category") + s1 = Series([10, 11, np.nan], dtype="category") + s2 = Series([np.nan, 1, 3, 2], dtype="category") - exp = pd.Series([10, 11, np.nan, np.nan, 1, 3, 2], dtype="object") + exp = Series([10, 11, np.nan, np.nan, 1, 3, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) def test_union_categorical_same_categories_different_order(self): # https://github.com/pandas-dev/pandas/issues/19096 - a = pd.Series(Categorical(["a", "b", "c"], categories=["a", "b", "c"])) - b = pd.Series(Categorical(["a", "b", "c"], categories=["b", "a", "c"])) + a = Series(Categorical(["a", "b", "c"], categories=["a", "b", "c"])) + b = Series(Categorical(["a", "b", "c"], categories=["b", "a", "c"])) result = pd.concat([a, b], ignore_index=True) - expected = pd.Series( + expected = Series( Categorical(["a", "b", "c", "a", "b", "c"], categories=["a", "b", "c"]) ) tm.assert_series_equal(result, expected) @@ -542,63 +542,63 @@ def test_concat_categorical_coercion(self): # GH 13524 # category + not-category => not-category - s1 = pd.Series([1, 2, np.nan], dtype="category") - s2 = pd.Series([2, 1, 2]) + s1 = Series([1, 2, np.nan], dtype="category") + s2 = Series([2, 1, 2]) - exp = pd.Series([1, 2, np.nan, 2, 1, 2], dtype="object") + exp = Series([1, 2, np.nan, 2, 1, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) # result shouldn't be affected by 1st elem dtype - exp = pd.Series([2, 1, 2, 1, 2, np.nan], dtype="object") + exp = Series([2, 1, 2, 1, 2, np.nan], dtype="object") tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) # all values are not in category => not-category - s1 = pd.Series([3, 2], dtype="category") - s2 = pd.Series([2, 1]) + s1 = Series([3, 2], dtype="category") + s2 = Series([2, 1]) - exp = pd.Series([3, 2, 2, 1]) + exp = Series([3, 2, 2, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - exp = pd.Series([2, 1, 3, 2]) + exp = Series([2, 1, 3, 2]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) # completely different categories => not-category - s1 = pd.Series([10, 11, np.nan], dtype="category") - s2 = pd.Series([1, 3, 2]) + s1 = Series([10, 11, np.nan], dtype="category") + s2 = Series([1, 3, 2]) - exp = pd.Series([10, 11, np.nan, 1, 3, 2], dtype="object") + exp = Series([10, 11, np.nan, 1, 3, 2], dtype="object") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - exp = pd.Series([1, 3, 2, 10, 11, np.nan], dtype="object") + exp = Series([1, 3, 2, 10, 11, np.nan], dtype="object") tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) # different dtype => not-category - s1 = pd.Series([10, 11, np.nan], dtype="category") - s2 = pd.Series(["a", "b", "c"]) + s1 = Series([10, 11, np.nan], dtype="category") + s2 = Series(["a", "b", "c"]) - exp = pd.Series([10, 11, np.nan, "a", "b", "c"]) + exp = Series([10, 11, np.nan, "a", "b", "c"]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - exp = pd.Series(["a", "b", "c", 10, 11, np.nan]) + exp = Series(["a", "b", "c", 10, 11, np.nan]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) # if normal series only contains NaN-likes => not-category - s1 = pd.Series([10, 11], dtype="category") - s2 = pd.Series([np.nan, np.nan, np.nan]) + s1 = Series([10, 11], dtype="category") + s2 = Series([np.nan, np.nan, np.nan]) - exp = pd.Series([10, 11, np.nan, np.nan, np.nan]) + exp = Series([10, 11, np.nan, np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - exp = pd.Series([np.nan, np.nan, np.nan, 10, 11]) + exp = Series([np.nan, np.nan, np.nan, 10, 11]) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) @@ -606,62 +606,62 @@ def test_concat_categorical_3elem_coercion(self): # GH 13524 # mixed dtypes => not-category - s1 = pd.Series([1, 2, np.nan], dtype="category") - s2 = pd.Series([2, 1, 2], dtype="category") - s3 = pd.Series([1, 2, 1, 2, np.nan]) + s1 = Series([1, 2, np.nan], dtype="category") + s2 = Series([2, 1, 2], dtype="category") + s3 = Series([1, 2, 1, 2, np.nan]) - exp = pd.Series([1, 2, np.nan, 2, 1, 2, 1, 2, 1, 2, np.nan], dtype="float") + exp = Series([1, 2, np.nan, 2, 1, 2, 1, 2, 1, 2, np.nan], dtype="float") tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) - exp = pd.Series([1, 2, 1, 2, np.nan, 1, 2, np.nan, 2, 1, 2], dtype="float") + exp = Series([1, 2, 1, 2, np.nan, 1, 2, np.nan, 2, 1, 2], dtype="float") tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) # values are all in either category => not-category - s1 = pd.Series([4, 5, 6], dtype="category") - s2 = pd.Series([1, 2, 3], dtype="category") - s3 = pd.Series([1, 3, 4]) + s1 = Series([4, 5, 6], dtype="category") + s2 = Series([1, 2, 3], dtype="category") + s3 = Series([1, 3, 4]) - exp = pd.Series([4, 5, 6, 1, 2, 3, 1, 3, 4]) + exp = Series([4, 5, 6, 1, 2, 3, 1, 3, 4]) tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) - exp = pd.Series([1, 3, 4, 4, 5, 6, 1, 2, 3]) + exp = Series([1, 3, 4, 4, 5, 6, 1, 2, 3]) tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) # values are all in either category => not-category - s1 = pd.Series([4, 5, 6], dtype="category") - s2 = pd.Series([1, 2, 3], dtype="category") - s3 = pd.Series([10, 11, 12]) + s1 = Series([4, 5, 6], dtype="category") + s2 = Series([1, 2, 3], dtype="category") + s3 = Series([10, 11, 12]) - exp = pd.Series([4, 5, 6, 1, 2, 3, 10, 11, 12]) + exp = Series([4, 5, 6, 1, 2, 3, 10, 11, 12]) tm.assert_series_equal(pd.concat([s1, s2, s3], ignore_index=True), exp) tm.assert_series_equal(s1.append([s2, s3], ignore_index=True), exp) - exp = pd.Series([10, 11, 12, 4, 5, 6, 1, 2, 3]) + exp = Series([10, 11, 12, 4, 5, 6, 1, 2, 3]) tm.assert_series_equal(pd.concat([s3, s1, s2], ignore_index=True), exp) tm.assert_series_equal(s3.append([s1, s2], ignore_index=True), exp) def test_concat_categorical_multi_coercion(self): # GH 13524 - s1 = pd.Series([1, 3], dtype="category") - s2 = pd.Series([3, 4], dtype="category") - s3 = pd.Series([2, 3]) - s4 = pd.Series([2, 2], dtype="category") - s5 = pd.Series([1, np.nan]) - s6 = pd.Series([1, 3, 2], dtype="category") + s1 = Series([1, 3], dtype="category") + s2 = Series([3, 4], dtype="category") + s3 = Series([2, 3]) + s4 = Series([2, 2], dtype="category") + s5 = Series([1, np.nan]) + s6 = Series([1, 3, 2], dtype="category") # mixed dtype, values are all in categories => not-category - exp = pd.Series([1, 3, 3, 4, 2, 3, 2, 2, 1, np.nan, 1, 3, 2]) + exp = Series([1, 3, 3, 4, 2, 3, 2, 2, 1, np.nan, 1, 3, 2]) res = pd.concat([s1, s2, s3, s4, s5, s6], ignore_index=True) tm.assert_series_equal(res, exp) res = s1.append([s2, s3, s4, s5, s6], ignore_index=True) tm.assert_series_equal(res, exp) - exp = pd.Series([1, 3, 2, 1, np.nan, 2, 2, 2, 3, 3, 4, 1, 3]) + exp = Series([1, 3, 2, 1, np.nan, 2, 2, 2, 3, 3, 4, 1, 3]) res = pd.concat([s6, s5, s4, s3, s2, s1], ignore_index=True) tm.assert_series_equal(res, exp) res = s6.append([s5, s4, s3, s2, s1], ignore_index=True) @@ -670,14 +670,14 @@ def test_concat_categorical_multi_coercion(self): def test_concat_categorical_ordered(self): # GH 13524 - s1 = pd.Series(pd.Categorical([1, 2, np.nan], ordered=True)) - s2 = pd.Series(pd.Categorical([2, 1, 2], ordered=True)) + s1 = Series(pd.Categorical([1, 2, np.nan], ordered=True)) + s2 = Series(pd.Categorical([2, 1, 2], ordered=True)) - exp = pd.Series(pd.Categorical([1, 2, np.nan, 2, 1, 2], ordered=True)) + exp = Series(pd.Categorical([1, 2, np.nan, 2, 1, 2], ordered=True)) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - exp = pd.Series( + exp = Series( pd.Categorical([1, 2, np.nan, 2, 1, 2, 1, 2, np.nan], ordered=True) ) tm.assert_series_equal(pd.concat([s1, s2, s1], ignore_index=True), exp) @@ -688,35 +688,35 @@ def test_concat_categorical_coercion_nan(self): # some edge cases # category + not-category => not category - s1 = pd.Series(np.array([np.nan, np.nan], dtype=np.float64), dtype="category") - s2 = pd.Series([np.nan, 1]) + s1 = Series(np.array([np.nan, np.nan], dtype=np.float64), dtype="category") + s2 = Series([np.nan, 1]) - exp = pd.Series([np.nan, np.nan, np.nan, 1]) + exp = Series([np.nan, np.nan, np.nan, 1]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) - s1 = pd.Series([1, np.nan], dtype="category") - s2 = pd.Series([np.nan, np.nan]) + s1 = Series([1, np.nan], dtype="category") + s2 = Series([np.nan, np.nan]) - exp = pd.Series([1, np.nan, np.nan, np.nan], dtype="float") + exp = Series([1, np.nan, np.nan, np.nan], dtype="float") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) # mixed dtype, all nan-likes => not-category - s1 = pd.Series([np.nan, np.nan], dtype="category") - s2 = pd.Series([np.nan, np.nan]) + s1 = Series([np.nan, np.nan], dtype="category") + s2 = Series([np.nan, np.nan]) - exp = pd.Series([np.nan, np.nan, np.nan, np.nan]) + exp = Series([np.nan, np.nan, np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), exp) tm.assert_series_equal(s2.append(s1, ignore_index=True), exp) # all category nan-likes => category - s1 = pd.Series([np.nan, np.nan], dtype="category") - s2 = pd.Series([np.nan, np.nan], dtype="category") + s1 = Series([np.nan, np.nan], dtype="category") + s2 = Series([np.nan, np.nan], dtype="category") - exp = pd.Series([np.nan, np.nan, np.nan, np.nan], dtype="category") + exp = Series([np.nan, np.nan, np.nan, np.nan], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) @@ -724,8 +724,8 @@ def test_concat_categorical_coercion_nan(self): def test_concat_categorical_empty(self): # GH 13524 - s1 = pd.Series([], dtype="category") - s2 = pd.Series([1, 2], dtype="category") + s1 = Series([], dtype="category") + s2 = Series([1, 2], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) tm.assert_series_equal(s1.append(s2, ignore_index=True), s2) @@ -733,14 +733,14 @@ def test_concat_categorical_empty(self): tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), s2) tm.assert_series_equal(s2.append(s1, ignore_index=True), s2) - s1 = pd.Series([], dtype="category") - s2 = pd.Series([], dtype="category") + s1 = Series([], dtype="category") + s2 = Series([], dtype="category") tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) tm.assert_series_equal(s1.append(s2, ignore_index=True), s2) - s1 = pd.Series([], dtype="category") - s2 = pd.Series([], dtype="object") + s1 = Series([], dtype="category") + s2 = Series([], dtype="object") # different dtype => not-category tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), s2) @@ -748,11 +748,11 @@ def test_concat_categorical_empty(self): tm.assert_series_equal(pd.concat([s2, s1], ignore_index=True), s2) tm.assert_series_equal(s2.append(s1, ignore_index=True), s2) - s1 = pd.Series([], dtype="category") - s2 = pd.Series([np.nan, np.nan]) + s1 = Series([], dtype="category") + s2 = Series([np.nan, np.nan]) # empty Series is ignored - exp = pd.Series([np.nan, np.nan]) + exp = Series([np.nan, np.nan]) tm.assert_series_equal(pd.concat([s1, s2], ignore_index=True), exp) tm.assert_series_equal(s1.append(s2, ignore_index=True), exp) @@ -939,7 +939,7 @@ def test_append_same_columns_type(self, index): # df wider than ser df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=index) ser_index = index[:2] - ser = pd.Series([7, 8], index=ser_index, name=2) + ser = Series([7, 8], index=ser_index, name=2) result = df.append(ser) expected = pd.DataFrame( [[1.0, 2.0, 3.0], [4, 5, 6], [7, 8, np.nan]], index=[0, 1, 2], columns=index @@ -950,7 +950,7 @@ def test_append_same_columns_type(self, index): ser_index = index index = index[:2] df = pd.DataFrame([[1, 2], [4, 5]], columns=index) - ser = pd.Series([7, 8, 9], index=ser_index, name=2) + ser = Series([7, 8, 9], index=ser_index, name=2) result = df.append(ser) expected = pd.DataFrame( [[1, 2, np.nan], [4, 5, np.nan], [7, 8, 9]], @@ -970,7 +970,7 @@ def test_append_different_columns_types(self, df_columns, series_index): # for errors raised when appending df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=df_columns) - ser = pd.Series([7, 8, 9], index=series_index, name=2) + ser = Series([7, 8, 9], index=series_index, name=2) result = df.append(ser) idx_diff = ser.index.difference(df_columns) @@ -1005,7 +1005,7 @@ def test_append_different_columns_types_raises( # appending without raising. df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=index_can_append) - ser = pd.Series([7, 8, 9], index=index_cannot_append_with_other, name=2) + ser = Series([7, 8, 9], index=index_cannot_append_with_other, name=2) msg = ( r"Expected tuple, got (int|long|float|str|" r"pandas._libs.interval.Interval)|" @@ -1018,7 +1018,7 @@ def test_append_different_columns_types_raises( df = pd.DataFrame( [[1, 2, 3], [4, 5, 6]], columns=index_cannot_append_with_other ) - ser = pd.Series([7, 8, 9], index=index_can_append, name=2) + ser = Series([7, 8, 9], index=index_can_append, name=2) with pytest.raises(TypeError, match=msg): df.append(ser) @@ -1122,7 +1122,7 @@ def test_append_empty_tz_frame_with_datetime64ns(self): # also test with typed value to append df = pd.DataFrame(columns=["a"]).astype("datetime64[ns, UTC]") result = df.append( - pd.Series({"a": pd.NaT}, dtype="datetime64[ns]"), ignore_index=True + Series({"a": pd.NaT}, dtype="datetime64[ns]"), ignore_index=True ) expected = pd.DataFrame({"a": [pd.NaT]}).astype("datetime64[ns]") tm.assert_frame_equal(result, expected) @@ -1986,16 +1986,16 @@ def test_concat_NaT_series(self): tm.assert_series_equal(result, expected) # without tz - x = pd.Series(pd.date_range("20151124 08:00", "20151124 09:00", freq="1h")) - y = pd.Series(pd.date_range("20151124 10:00", "20151124 11:00", freq="1h")) + x = Series(pd.date_range("20151124 08:00", "20151124 09:00", freq="1h")) + y = Series(pd.date_range("20151124 10:00", "20151124 11:00", freq="1h")) y[:] = pd.NaT - expected = pd.Series([x[0], x[1], pd.NaT, pd.NaT]) + expected = Series([x[0], x[1], pd.NaT, pd.NaT]) result = pd.concat([x, y], ignore_index=True) tm.assert_series_equal(result, expected) # all NaT without tz x[:] = pd.NaT - expected = pd.Series(pd.NaT, index=range(4), dtype="datetime64[ns]") + expected = Series(pd.NaT, index=range(4), dtype="datetime64[ns]") result = pd.concat([x, y], ignore_index=True) tm.assert_series_equal(result, expected) @@ -2075,13 +2075,13 @@ def test_concat_tz_series_with_datetimelike(self): pd.Timestamp("2011-02-01", tz="US/Eastern"), ] y = [pd.Timedelta("1 day"), pd.Timedelta("2 day")] - result = concat([pd.Series(x), pd.Series(y)], ignore_index=True) - tm.assert_series_equal(result, pd.Series(x + y, dtype="object")) + result = concat([Series(x), Series(y)], ignore_index=True) + tm.assert_series_equal(result, Series(x + y, dtype="object")) # tz and period y = [pd.Period("2011-03", freq="M"), pd.Period("2011-04", freq="M")] - result = concat([pd.Series(x), pd.Series(y)], ignore_index=True) - tm.assert_series_equal(result, pd.Series(x + y, dtype="object")) + result = concat([Series(x), Series(y)], ignore_index=True) + tm.assert_series_equal(result, Series(x + y, dtype="object")) def test_concat_tz_series_tzlocal(self): # see gh-13583 @@ -2094,8 +2094,8 @@ def test_concat_tz_series_tzlocal(self): pd.Timestamp("2012-02-01", tz=dateutil.tz.tzlocal()), ] - result = concat([pd.Series(x), pd.Series(y)], ignore_index=True) - tm.assert_series_equal(result, pd.Series(x + y)) + result = concat([Series(x), Series(y)], ignore_index=True) + tm.assert_series_equal(result, Series(x + y)) assert result.dtype == "datetime64[ns, tzlocal()]" @pytest.mark.parametrize("tz1", [None, "UTC"]) @@ -2111,7 +2111,7 @@ def test_concat_NaT_dataframes_all_NaT_axis_0(self, tz1, tz2, s): second = pd.DataFrame([s]).apply(lambda x: x.dt.tz_localize(tz2)) result = pd.concat([first, second], axis=0) - expected = pd.DataFrame(pd.Series([pd.NaT, pd.NaT, s], index=[0, 1, 0])) + expected = pd.DataFrame(Series([pd.NaT, pd.NaT, s], index=[0, 1, 0])) expected = expected.apply(lambda x: x.dt.tz_localize(tz2)) if tz1 != tz2: expected = expected.astype(object) @@ -2123,12 +2123,12 @@ def test_concat_NaT_dataframes_all_NaT_axis_0(self, tz1, tz2, s): def test_concat_NaT_dataframes_all_NaT_axis_1(self, tz1, tz2): # GH 12396 - first = pd.DataFrame(pd.Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1)) - second = pd.DataFrame(pd.Series([pd.NaT]).dt.tz_localize(tz2), columns=[1]) + first = pd.DataFrame(Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1)) + second = pd.DataFrame(Series([pd.NaT]).dt.tz_localize(tz2), columns=[1]) expected = pd.DataFrame( { - 0: pd.Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1), - 1: pd.Series([pd.NaT, pd.NaT]).dt.tz_localize(tz2), + 0: Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1), + 1: Series([pd.NaT, pd.NaT]).dt.tz_localize(tz2), } ) result = pd.concat([first, second], axis=1) @@ -2140,7 +2140,7 @@ def test_concat_NaT_series_dataframe_all_NaT(self, tz1, tz2): # GH 12396 # tz-naive - first = pd.Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1) + first = Series([pd.NaT, pd.NaT]).dt.tz_localize(tz1) second = pd.DataFrame( [ [pd.Timestamp("2015/01/01", tz=tz2)], @@ -2225,8 +2225,8 @@ 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", dtype="float64") + s1 = Series([1, 2, 3], name="x") + s2 = 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]}, @@ -2234,16 +2234,16 @@ 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", dtype="float64") + s1 = Series([1, 2, 3], name="x") + s2 = Series(name="y", dtype="float64") res = pd.concat([s1, s2], axis=0) # name will be reset - exp = pd.Series([1, 2, 3]) + exp = Series([1, 2, 3]) tm.assert_series_equal(res, exp) # empty Series with no name - s1 = pd.Series([1, 2, 3], name="x") - s2 = pd.Series(name=None, dtype="float64") + s1 = Series([1, 2, 3], name="x") + s2 = 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]}, @@ -2263,7 +2263,7 @@ def test_concat_empty_series_timelike(self, tz, values): expected = DataFrame( { - 0: pd.Series([pd.NaT] * len(values), dtype="M8[ns]").dt.tz_localize(tz), + 0: Series([pd.NaT] * len(values), dtype="M8[ns]").dt.tz_localize(tz), 1: values, } ) @@ -2272,8 +2272,8 @@ def test_concat_empty_series_timelike(self, tz, values): def test_default_index(self): # is_series and ignore_index - s1 = pd.Series([1, 2, 3], name="x") - s2 = pd.Series([4, 5, 6], name="y") + s1 = Series([1, 2, 3], name="x") + s2 = Series([4, 5, 6], name="y") res = pd.concat([s1, s2], axis=1, ignore_index=True) assert isinstance(res.columns, pd.RangeIndex) exp = pd.DataFrame([[1, 4], [2, 5], [3, 6]]) @@ -2282,8 +2282,8 @@ def test_default_index(self): tm.assert_frame_equal(res, exp, check_index_type=True, check_column_type=True) # is_series and all inputs have no names - s1 = pd.Series([1, 2, 3]) - s2 = pd.Series([4, 5, 6]) + s1 = Series([1, 2, 3]) + s2 = Series([4, 5, 6]) res = pd.concat([s1, s2], axis=1, ignore_index=False) assert isinstance(res.columns, pd.RangeIndex) exp = pd.DataFrame([[1, 4], [2, 5], [3, 6]]) @@ -2499,9 +2499,9 @@ def test_concat_categoricalindex(self): # GH 16111, categories that aren't lexsorted categories = [9, 0, 1, 2, 3] - a = pd.Series(1, index=pd.CategoricalIndex([9, 0], categories=categories)) - b = pd.Series(2, index=pd.CategoricalIndex([0, 1], categories=categories)) - c = pd.Series(3, index=pd.CategoricalIndex([1, 2], categories=categories)) + a = Series(1, index=pd.CategoricalIndex([9, 0], categories=categories)) + b = Series(2, index=pd.CategoricalIndex([0, 1], categories=categories)) + c = Series(3, index=pd.CategoricalIndex([1, 2], categories=categories)) result = pd.concat([a, b, c], axis=1) @@ -2596,25 +2596,25 @@ def test_concat_datetime_timezone(self): tm.assert_frame_equal(result, expected) def test_concat_different_extension_dtypes_upcasts(self): - a = pd.Series(pd.core.arrays.integer_array([1, 2])) - b = pd.Series(to_decimal([1, 2])) + a = Series(pd.core.arrays.integer_array([1, 2])) + b = Series(to_decimal([1, 2])) result = pd.concat([a, b], ignore_index=True) - expected = pd.Series([1, 2, Decimal(1), Decimal(2)], dtype=object) + expected = Series([1, 2, Decimal(1), Decimal(2)], dtype=object) tm.assert_series_equal(result, expected) def test_concat_odered_dict(self): # GH 21510 expected = pd.concat( - [pd.Series(range(3)), pd.Series(range(4))], keys=["First", "Another"] + [Series(range(3)), Series(range(4))], keys=["First", "Another"] ) result = pd.concat( - dict([("First", pd.Series(range(3))), ("Another", pd.Series(range(4)))]) + dict([("First", Series(range(3))), ("Another", Series(range(4)))]) ) tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("pdt", [pd.Series, pd.DataFrame]) +@pytest.mark.parametrize("pdt", [Series, pd.DataFrame]) @pytest.mark.parametrize("dt", np.sctypes["float"]) def test_concat_no_unnecessary_upcast(dt, pdt): # GH 13247 @@ -2654,8 +2654,8 @@ def test_concat_empty_and_non_empty_frame_regression(): def test_concat_empty_and_non_empty_series_regression(): # GH 18187 regression test - s1 = pd.Series([1]) - s2 = pd.Series([], dtype=object) + s1 = Series([1]) + s2 = Series([], dtype=object) expected = s1 result = pd.concat([s1, s2]) @@ -2742,19 +2742,19 @@ def test_concat_aligned_sort_does_not_raise(): @pytest.mark.parametrize("s1name,s2name", [(np.int64(190), (43, 0)), (190, (43, 0))]) def test_concat_series_name_npscalar_tuple(s1name, s2name): # GH21015 - s1 = pd.Series({"a": 1, "b": 2}, name=s1name) - s2 = pd.Series({"c": 5, "d": 6}, name=s2name) + s1 = Series({"a": 1, "b": 2}, name=s1name) + s2 = Series({"c": 5, "d": 6}, name=s2name) result = pd.concat([s1, s2]) - expected = pd.Series({"a": 1, "b": 2, "c": 5, "d": 6}) + expected = Series({"a": 1, "b": 2, "c": 5, "d": 6}) tm.assert_series_equal(result, expected) def test_concat_categorical_tz(): # GH-23816 - a = pd.Series(pd.date_range("2017-01-01", periods=2, tz="US/Pacific")) - b = pd.Series(["a", "b"], dtype="category") + a = Series(pd.date_range("2017-01-01", periods=2, tz="US/Pacific")) + b = Series(["a", "b"], dtype="category") result = pd.concat([a, b], ignore_index=True) - expected = pd.Series( + expected = Series( [ pd.Timestamp("2017-01-01", tz="US/Pacific"), pd.Timestamp("2017-01-02", tz="US/Pacific"), @@ -2769,13 +2769,13 @@ def test_concat_categorical_unchanged(): # GH-12007 # test fix for when concat on categorical and float # coerces dtype categorical -> float - df = pd.DataFrame(pd.Series(["a", "b", "c"], dtype="category", name="A")) - ser = pd.Series([0, 1, 2], index=[0, 1, 3], name="B") + df = pd.DataFrame(Series(["a", "b", "c"], dtype="category", name="A")) + ser = Series([0, 1, 2], index=[0, 1, 3], name="B") result = pd.concat([df, ser], axis=1) expected = pd.DataFrame( { - "A": pd.Series(["a", "b", "c", np.nan], dtype="category"), - "B": pd.Series([0, 1, np.nan, 2], dtype="float"), + "A": Series(["a", "b", "c", np.nan], dtype="category"), + "B": Series([0, 1, np.nan, 2], dtype="float"), } ) tm.assert_equal(result, expected) @@ -2808,7 +2808,7 @@ def test_concat_empty_df_object_dtype(): def test_concat_sparse(): # GH 23557 - a = pd.Series(SparseArray([0, 1, 2])) + a = Series(SparseArray([0, 1, 2])) expected = pd.DataFrame(data=[[0, 0], [1, 1], [2, 2]]).astype( pd.SparseDtype(np.int64, 0) ) @@ -2818,9 +2818,9 @@ def test_concat_sparse(): def test_concat_dense_sparse(): # GH 30668 - a = pd.Series(pd.arrays.SparseArray([1, None]), dtype=float) - b = pd.Series([1], dtype=float) - expected = pd.Series(data=[1, None, 1], index=[0, 1, 0]).astype( + a = Series(pd.arrays.SparseArray([1, None]), dtype=float) + b = Series([1], dtype=float) + expected = Series(data=[1, None, 1], index=[0, 1, 0]).astype( pd.SparseDtype(np.float64, None) ) result = pd.concat([a, b], axis=0) @@ -3196,11 +3196,11 @@ def test_concat_axis_parameter(self): concatted_1 = pd.concat([df1, df2], axis=1) tm.assert_frame_equal(concatted_1, expected_columns) - series1 = pd.Series([0.1, 0.2]) - series2 = pd.Series([0.3, 0.4]) + series1 = Series([0.1, 0.2]) + series2 = Series([0.3, 0.4]) # Index/row/0 Series - expected_index_series = pd.Series([0.1, 0.2, 0.3, 0.4], index=[0, 1, 0, 1]) + expected_index_series = Series([0.1, 0.2, 0.3, 0.4], index=[0, 1, 0, 1]) concatted_index_series = pd.concat([series1, series2], axis="index") tm.assert_series_equal(concatted_index_series, expected_index_series) diff --git a/pandas/tests/reshape/test_cut.py b/pandas/tests/reshape/test_cut.py index 4d2195da85a13..e6091a63b3e97 100644 --- a/pandas/tests/reshape/test_cut.py +++ b/pandas/tests/reshape/test_cut.py @@ -668,9 +668,9 @@ def test_cut_unordered_with_missing_labels_raises_error(): def test_cut_unordered_with_series_labels(): # https://github.com/pandas-dev/pandas/issues/36603 - s = pd.Series([1, 2, 3, 4, 5]) - bins = pd.Series([0, 2, 4, 6]) - labels = pd.Series(["a", "b", "c"]) + s = Series([1, 2, 3, 4, 5]) + bins = Series([0, 2, 4, 6]) + labels = Series(["a", "b", "c"]) result = pd.cut(s, bins=bins, labels=labels, ordered=False) - expected = pd.Series(["a", "a", "b", "b", "c"], dtype="category") + expected = Series(["a", "a", "b", "b", "c"], dtype="category") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 67b3151b0ff9c..943a7d0a3cf86 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -707,7 +707,7 @@ def test_pivot_periods_with_margins(self): [ ["baz", "zoo"], np.array(["baz", "zoo"]), - pd.Series(["baz", "zoo"]), + Series(["baz", "zoo"]), pd.Index(["baz", "zoo"]), ], ) @@ -743,7 +743,7 @@ def test_pivot_with_list_like_values(self, values, method): [ ["bar", "baz"], np.array(["bar", "baz"]), - pd.Series(["bar", "baz"]), + Series(["bar", "baz"]), pd.Index(["bar", "baz"]), ], ) diff --git a/pandas/tests/reshape/test_union_categoricals.py b/pandas/tests/reshape/test_union_categoricals.py index 8918d19e4ba7b..f6a4f8c0cf601 100644 --- a/pandas/tests/reshape/test_union_categoricals.py +++ b/pandas/tests/reshape/test_union_categoricals.py @@ -331,7 +331,7 @@ def test_union_categoricals_sort_false(self): def test_union_categorical_unwrap(self): # GH 14173 c1 = Categorical(["a", "b"]) - c2 = pd.Series(["b", "c"], dtype="category") + c2 = Series(["b", "c"], dtype="category") result = union_categoricals([c1, c2]) expected = Categorical(["a", "b", "b", "c"]) tm.assert_categorical_equal(result, expected) diff --git a/pandas/tests/series/apply/test_series_apply.py b/pandas/tests/series/apply/test_series_apply.py index ce8759c4ba76d..61ebd2fcb3a27 100644 --- a/pandas/tests/series/apply/test_series_apply.py +++ b/pandas/tests/series/apply/test_series_apply.py @@ -92,56 +92,56 @@ def func(x): def test_apply_box(self): # ufunc will not be boxed. Same test cases as the test_map_box vals = [pd.Timestamp("2011-01-01"), pd.Timestamp("2011-01-02")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "datetime64[ns]" # boxed value must be Timestamp instance res = s.apply(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}") - exp = pd.Series(["Timestamp_1_None", "Timestamp_2_None"]) + exp = Series(["Timestamp_1_None", "Timestamp_2_None"]) tm.assert_series_equal(res, exp) vals = [ pd.Timestamp("2011-01-01", tz="US/Eastern"), pd.Timestamp("2011-01-02", tz="US/Eastern"), ] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "datetime64[ns, US/Eastern]" res = s.apply(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}") - exp = pd.Series(["Timestamp_1_US/Eastern", "Timestamp_2_US/Eastern"]) + exp = Series(["Timestamp_1_US/Eastern", "Timestamp_2_US/Eastern"]) tm.assert_series_equal(res, exp) # timedelta vals = [pd.Timedelta("1 days"), pd.Timedelta("2 days")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "timedelta64[ns]" res = s.apply(lambda x: f"{type(x).__name__}_{x.days}") - exp = pd.Series(["Timedelta_1", "Timedelta_2"]) + exp = Series(["Timedelta_1", "Timedelta_2"]) tm.assert_series_equal(res, exp) # period vals = [pd.Period("2011-01-01", freq="M"), pd.Period("2011-01-02", freq="M")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "Period[M]" res = s.apply(lambda x: f"{type(x).__name__}_{x.freqstr}") - exp = pd.Series(["Period_M", "Period_M"]) + exp = Series(["Period_M", "Period_M"]) tm.assert_series_equal(res, exp) def test_apply_datetimetz(self): values = pd.date_range("2011-01-01", "2011-01-02", freq="H").tz_localize( "Asia/Tokyo" ) - s = pd.Series(values, name="XX") + s = Series(values, name="XX") result = s.apply(lambda x: x + pd.offsets.Day()) exp_values = pd.date_range("2011-01-02", "2011-01-03", freq="H").tz_localize( "Asia/Tokyo" ) - exp = pd.Series(exp_values, name="XX") + exp = Series(exp_values, name="XX") tm.assert_series_equal(result, exp) # change dtype # GH 14506 : Returned dtype changed from int32 to int64 result = s.apply(lambda x: x.hour) - exp = pd.Series(list(range(24)) + [0], name="XX", dtype=np.int64) + exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64) tm.assert_series_equal(result, exp) # not vectorized @@ -151,7 +151,7 @@ def f(x): return str(x.tz) result = s.map(f) - exp = pd.Series(["Asia/Tokyo"] * 25, name="XX") + exp = Series(["Asia/Tokyo"] * 25, name="XX") tm.assert_series_equal(result, exp) def test_apply_dict_depr(self): @@ -167,34 +167,34 @@ def test_apply_dict_depr(self): def test_apply_categorical(self): values = pd.Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True) - ser = pd.Series(values, name="XX", index=list("abcdefg")) + ser = Series(values, name="XX", index=list("abcdefg")) result = ser.apply(lambda x: x.lower()) # should be categorical dtype when the number of categories are # the same values = pd.Categorical(list("abbabcd"), categories=list("dcba"), ordered=True) - exp = pd.Series(values, name="XX", index=list("abcdefg")) + exp = Series(values, name="XX", index=list("abcdefg")) tm.assert_series_equal(result, exp) tm.assert_categorical_equal(result.values, exp.values) result = ser.apply(lambda x: "A") - exp = pd.Series(["A"] * 7, name="XX", index=list("abcdefg")) + exp = Series(["A"] * 7, name="XX", index=list("abcdefg")) tm.assert_series_equal(result, exp) assert result.dtype == object @pytest.mark.parametrize("series", [["1-1", "1-1", np.NaN], ["1-1", "1-2", np.NaN]]) def test_apply_categorical_with_nan_values(self, series): # GH 20714 bug fixed in: GH 24275 - s = pd.Series(series, dtype="category") + s = Series(series, dtype="category") result = s.apply(lambda x: x.split("-")[0]) result = result.astype(object) - expected = pd.Series(["1", "1", np.NaN], dtype="category") + expected = Series(["1", "1", np.NaN], dtype="category") expected = expected.astype(object) tm.assert_series_equal(result, expected) def test_apply_empty_integer_series_with_datetime_index(self): # GH 21245 - s = pd.Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int) + s = Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int) result = s.apply(lambda x: x) tm.assert_series_equal(result, s) @@ -447,9 +447,9 @@ def test_agg_cython_table_raises(self, series, func, expected): def test_series_apply_no_suffix_index(self): # GH36189 - s = pd.Series([4] * 3) + s = Series([4] * 3) result = s.apply(["sum", lambda x: x.sum(), lambda x: x.sum()]) - expected = pd.Series([12, 12, 12], index=["sum", "", ""]) + expected = Series([12, 12, 12], index=["sum", "", ""]) tm.assert_series_equal(result, expected) @@ -517,7 +517,7 @@ def test_map_empty(self, index): s = Series(index) result = s.map({}) - expected = pd.Series(np.nan, index=s.index) + expected = Series(np.nan, index=s.index) tm.assert_series_equal(result, expected) def test_map_compat(self): @@ -570,7 +570,7 @@ def test_map_dict_with_tuple_keys(self): label_mappings = {(1,): "A", (2,): "B", (3, 4): "A", (5, 6): "B"} df["labels"] = df["a"].map(label_mappings) - df["expected_labels"] = pd.Series(["A", "B", "A", "B"], index=df.index) + df["expected_labels"] = Series(["A", "B", "A", "B"], index=df.index) # All labels should be filled now tm.assert_series_equal(df["labels"], df["expected_labels"], check_names=False) @@ -651,53 +651,53 @@ def __missing__(self, key): def test_map_box(self): vals = [pd.Timestamp("2011-01-01"), pd.Timestamp("2011-01-02")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "datetime64[ns]" # boxed value must be Timestamp instance res = s.apply(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}") - exp = pd.Series(["Timestamp_1_None", "Timestamp_2_None"]) + exp = Series(["Timestamp_1_None", "Timestamp_2_None"]) tm.assert_series_equal(res, exp) vals = [ pd.Timestamp("2011-01-01", tz="US/Eastern"), pd.Timestamp("2011-01-02", tz="US/Eastern"), ] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "datetime64[ns, US/Eastern]" res = s.apply(lambda x: f"{type(x).__name__}_{x.day}_{x.tz}") - exp = pd.Series(["Timestamp_1_US/Eastern", "Timestamp_2_US/Eastern"]) + exp = Series(["Timestamp_1_US/Eastern", "Timestamp_2_US/Eastern"]) tm.assert_series_equal(res, exp) # timedelta vals = [pd.Timedelta("1 days"), pd.Timedelta("2 days")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "timedelta64[ns]" res = s.apply(lambda x: f"{type(x).__name__}_{x.days}") - exp = pd.Series(["Timedelta_1", "Timedelta_2"]) + exp = Series(["Timedelta_1", "Timedelta_2"]) tm.assert_series_equal(res, exp) # period vals = [pd.Period("2011-01-01", freq="M"), pd.Period("2011-01-02", freq="M")] - s = pd.Series(vals) + s = Series(vals) assert s.dtype == "Period[M]" res = s.apply(lambda x: f"{type(x).__name__}_{x.freqstr}") - exp = pd.Series(["Period_M", "Period_M"]) + exp = Series(["Period_M", "Period_M"]) tm.assert_series_equal(res, exp) def test_map_categorical(self): values = pd.Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True) - s = pd.Series(values, name="XX", index=list("abcdefg")) + s = Series(values, name="XX", index=list("abcdefg")) result = s.map(lambda x: x.lower()) exp_values = pd.Categorical( list("abbabcd"), categories=list("dcba"), ordered=True ) - exp = pd.Series(exp_values, name="XX", index=list("abcdefg")) + exp = Series(exp_values, name="XX", index=list("abcdefg")) tm.assert_series_equal(result, exp) tm.assert_categorical_equal(result.values, exp_values) result = s.map(lambda x: "A") - exp = pd.Series(["A"] * 7, name="XX", index=list("abcdefg")) + exp = Series(["A"] * 7, name="XX", index=list("abcdefg")) tm.assert_series_equal(result, exp) assert result.dtype == object @@ -708,20 +708,20 @@ def test_map_datetimetz(self): values = pd.date_range("2011-01-01", "2011-01-02", freq="H").tz_localize( "Asia/Tokyo" ) - s = pd.Series(values, name="XX") + s = Series(values, name="XX") # keep tz result = s.map(lambda x: x + pd.offsets.Day()) exp_values = pd.date_range("2011-01-02", "2011-01-03", freq="H").tz_localize( "Asia/Tokyo" ) - exp = pd.Series(exp_values, name="XX") + exp = Series(exp_values, name="XX") tm.assert_series_equal(result, exp) # change dtype # GH 14506 : Returned dtype changed from int32 to int64 result = s.map(lambda x: x.hour) - exp = pd.Series(list(range(24)) + [0], name="XX", dtype=np.int64) + exp = Series(list(range(24)) + [0], name="XX", dtype=np.int64) tm.assert_series_equal(result, exp) with pytest.raises(NotImplementedError): @@ -734,7 +734,7 @@ def f(x): return str(x.tz) result = s.map(f) - exp = pd.Series(["Asia/Tokyo"] * 25, name="XX") + exp = Series(["Asia/Tokyo"] * 25, name="XX") tm.assert_series_equal(result, exp) @pytest.mark.parametrize( @@ -747,10 +747,10 @@ def f(x): ) def test_map_missing_mixed(self, vals, mapping, exp): # GH20495 - s = pd.Series(vals + [np.nan]) + s = Series(vals + [np.nan]) result = s.map(mapping) - tm.assert_series_equal(result, pd.Series(exp)) + tm.assert_series_equal(result, Series(exp)) @pytest.mark.parametrize( "dti,exp", @@ -769,26 +769,26 @@ def test_apply_series_on_date_time_index_aware_series(self, dti, exp): # GH 25959 # Calling apply on a localized time series should not cause an error index = dti.tz_localize("UTC").index - result = pd.Series(index).apply(lambda x: pd.Series([1, 2])) + result = Series(index).apply(lambda x: Series([1, 2])) tm.assert_frame_equal(result, exp) def test_apply_scaler_on_date_time_index_aware_series(self): # GH 25959 # Calling apply on a localized time series should not cause an error series = tm.makeTimeSeries(nper=30).tz_localize("UTC") - result = pd.Series(series.index).apply(lambda x: 1) - tm.assert_series_equal(result, pd.Series(np.ones(30), dtype="int64")) + result = Series(series.index).apply(lambda x: 1) + tm.assert_series_equal(result, Series(np.ones(30), dtype="int64")) def test_map_float_to_string_precision(self): # GH 13228 - ser = pd.Series(1 / 3) + ser = Series(1 / 3) result = ser.map(lambda val: str(val)).to_dict() expected = {0: "0.3333333333333333"} assert result == expected def test_map_with_invalid_na_action_raises(self): # https://github.com/pandas-dev/pandas/issues/32815 - s = pd.Series([1, 2, 3]) + s = Series([1, 2, 3]) msg = "na_action must either be 'ignore' or None" with pytest.raises(ValueError, match=msg): s.map(lambda x: x, na_action="____") diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index 1801d13e75565..2e3d67786afdc 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -552,7 +552,7 @@ def test_indexing_over_size_cutoff_period_index(monkeypatch): idx = pd.period_range("1/1/2000", freq="T", periods=n) assert idx._engine.over_size_threshold - s = pd.Series(np.random.randn(len(idx)), index=idx) + s = Series(np.random.randn(len(idx)), index=idx) pos = n - 1 timestamp = idx[pos] diff --git a/pandas/tests/series/indexing/test_getitem.py b/pandas/tests/series/indexing/test_getitem.py index 5b585e8802752..06c14a95ab04e 100644 --- a/pandas/tests/series/indexing/test_getitem.py +++ b/pandas/tests/series/indexing/test_getitem.py @@ -90,7 +90,7 @@ def test_getitem_intlist_intindex_periodvalues(self): ser = Series(period_range("2000-01-01", periods=10, freq="D")) result = ser[[2, 4]] - exp = pd.Series( + exp = Series( [pd.Period("2000-01-03", freq="D"), pd.Period("2000-01-05", freq="D")], index=[2, 4], dtype="Period[D]", @@ -134,6 +134,6 @@ def test_getitem_generator(string_series): def test_getitem_ndim_deprecated(): - s = pd.Series([0, 1]) + s = Series([0, 1]) with tm.assert_produces_warning(FutureWarning): s[:, None] diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index fbdac2bb2d8e8..3d927a80a157c 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -132,7 +132,7 @@ def test_getitem_fancy(string_series, object_series): def test_type_promotion(): # GH12599 - s = pd.Series(dtype=object) + s = Series(dtype=object) s["a"] = pd.Timestamp("2016-01-01") s["b"] = 3.0 s["c"] = "foo" @@ -144,14 +144,14 @@ def test_type_promotion(): "result_1, duplicate_item, expected_1", [ [ - pd.Series({1: 12, 2: [1, 2, 2, 3]}), - pd.Series({1: 313}), - pd.Series({1: 12}, dtype=object), + Series({1: 12, 2: [1, 2, 2, 3]}), + Series({1: 313}), + Series({1: 12}, dtype=object), ], [ - pd.Series({1: [1, 2, 3], 2: [1, 2, 2, 3]}), - pd.Series({1: [1, 2, 3]}), - pd.Series({1: [1, 2, 3]}), + Series({1: [1, 2, 3], 2: [1, 2, 2, 3]}), + Series({1: [1, 2, 3]}), + Series({1: [1, 2, 3]}), ], ], ) @@ -205,7 +205,7 @@ def test_series_box_timestamp(): def test_series_box_timedelta(): rng = pd.timedelta_range("1 day 1 s", periods=5, freq="h") - ser = pd.Series(rng) + ser = Series(rng) assert isinstance(ser[0], Timedelta) assert isinstance(ser.at[1], Timedelta) assert isinstance(ser.iat[2], Timedelta) @@ -262,7 +262,7 @@ def test_setitem_ambiguous_keyerror(): def test_getitem_dataframe(): rng = list(range(10)) - s = pd.Series(10, index=rng) + s = Series(10, index=rng) df = pd.DataFrame(rng, index=rng) msg = ( "Indexing a Series with DataFrame is not supported, " @@ -299,15 +299,15 @@ def test_setitem(datetime_series, string_series): def test_setitem_empty_series(): # Test for issue #10193 key = pd.Timestamp("2012-01-01") - series = pd.Series(dtype=object) + series = Series(dtype=object) series[key] = 47 - expected = pd.Series(47, [key]) + expected = Series(47, [key]) tm.assert_series_equal(series, expected) # GH#33573 our index should retain its freq - series = pd.Series([], pd.DatetimeIndex([], freq="D"), dtype=object) + series = Series([], pd.DatetimeIndex([], freq="D"), dtype=object) series[key] = 47 - expected = pd.Series(47, pd.DatetimeIndex([key], freq="D")) + expected = Series(47, pd.DatetimeIndex([key], freq="D")) tm.assert_series_equal(series, expected) assert series.index.freq == expected.index.freq @@ -365,7 +365,7 @@ def test_setslice(datetime_series): def test_2d_to_1d_assignment_raises(): x = np.random.randn(2, 2) - y = pd.Series(range(2)) + y = Series(range(2)) msg = "|".join( [ @@ -409,13 +409,13 @@ def test_basic_getitem_setitem_corner(datetime_series): @pytest.mark.parametrize("tz", ["US/Eastern", "UTC", "Asia/Tokyo"]) def test_setitem_with_tz(tz): - orig = pd.Series(pd.date_range("2016-01-01", freq="H", periods=3, tz=tz)) + orig = Series(pd.date_range("2016-01-01", freq="H", periods=3, tz=tz)) assert orig.dtype == f"datetime64[ns, {tz}]" # scalar s = orig.copy() s[1] = pd.Timestamp("2011-01-01", tz=tz) - exp = pd.Series( + exp = Series( [ pd.Timestamp("2016-01-01 00:00", tz=tz), pd.Timestamp("2011-01-01 00:00", tz=tz), @@ -433,14 +433,14 @@ def test_setitem_with_tz(tz): tm.assert_series_equal(s, exp) # vector - vals = pd.Series( + vals = Series( [pd.Timestamp("2011-01-01", tz=tz), pd.Timestamp("2012-01-01", tz=tz)], index=[1, 2], ) assert vals.dtype == f"datetime64[ns, {tz}]" s[[1, 2]] = vals - exp = pd.Series( + exp = Series( [ pd.Timestamp("2016-01-01 00:00", tz=tz), pd.Timestamp("2011-01-01 00:00", tz=tz), @@ -461,13 +461,13 @@ def test_setitem_with_tz(tz): def test_setitem_with_tz_dst(): # GH XXX TODO: fill in GH ref tz = "US/Eastern" - orig = pd.Series(pd.date_range("2016-11-06", freq="H", periods=3, tz=tz)) + orig = Series(pd.date_range("2016-11-06", freq="H", periods=3, tz=tz)) assert orig.dtype == f"datetime64[ns, {tz}]" # scalar s = orig.copy() s[1] = pd.Timestamp("2011-01-01", tz=tz) - exp = pd.Series( + exp = Series( [ pd.Timestamp("2016-11-06 00:00-04:00", tz=tz), pd.Timestamp("2011-01-01 00:00-05:00", tz=tz), @@ -485,14 +485,14 @@ def test_setitem_with_tz_dst(): tm.assert_series_equal(s, exp) # vector - vals = pd.Series( + vals = Series( [pd.Timestamp("2011-01-01", tz=tz), pd.Timestamp("2012-01-01", tz=tz)], index=[1, 2], ) assert vals.dtype == f"datetime64[ns, {tz}]" s[[1, 2]] = vals - exp = pd.Series( + exp = Series( [ pd.Timestamp("2016-11-06 00:00", tz=tz), pd.Timestamp("2011-01-01 00:00", tz=tz), @@ -547,7 +547,7 @@ def test_categorical_assigning_ops(): def test_getitem_categorical_str(): # GH#31765 - ser = pd.Series(range(5), index=pd.Categorical(["a", "b", "c", "a", "b"])) + ser = Series(range(5), index=pd.Categorical(["a", "b", "c", "a", "b"])) result = ser["a"] expected = ser.iloc[[0, 3]] tm.assert_series_equal(result, expected) @@ -646,7 +646,7 @@ def test_timedelta_assignment(): # GH 14155 s = Series(10 * [np.timedelta64(10, "m")]) s.loc[[1, 2, 3]] = np.timedelta64(20, "m") - expected = pd.Series(10 * [np.timedelta64(10, "m")]) + expected = Series(10 * [np.timedelta64(10, "m")]) expected.loc[[1, 2, 3]] = pd.Timedelta(np.timedelta64(20, "m")) tm.assert_series_equal(s, expected) @@ -665,8 +665,8 @@ def test_dt64_series_assign_nat(nat_val, should_cast, tz): # into a datetime64 series. Others should coerce to object # and retain their dtypes. dti = pd.date_range("2016-01-01", periods=3, tz=tz) - base = pd.Series(dti) - expected = pd.Series([pd.NaT] + list(dti[1:]), dtype=dti.dtype) + base = Series(dti) + expected = Series([pd.NaT] + list(dti[1:]), dtype=dti.dtype) if not should_cast: expected = expected.astype(object) @@ -695,8 +695,8 @@ def test_td64_series_assign_nat(nat_val, should_cast): # some nat-like values should be cast to timedelta64 when inserting # into a timedelta64 series. Others should coerce to object # and retain their dtypes. - base = pd.Series([0, 1, 2], dtype="m8[ns]") - expected = pd.Series([pd.NaT, 1, 2], dtype="m8[ns]") + base = Series([0, 1, 2], dtype="m8[ns]") + expected = Series([pd.NaT, 1, 2], dtype="m8[ns]") if not should_cast: expected = expected.astype(object) @@ -723,14 +723,14 @@ def test_td64_series_assign_nat(nat_val, should_cast): ) def test_append_timedelta_does_not_cast(td): # GH#22717 inserting a Timedelta should _not_ cast to int64 - expected = pd.Series(["x", td], index=[0, "td"], dtype=object) + expected = Series(["x", td], index=[0, "td"], dtype=object) - ser = pd.Series(["x"]) + ser = Series(["x"]) ser["td"] = td tm.assert_series_equal(ser, expected) assert isinstance(ser["td"], pd.Timedelta) - ser = pd.Series(["x"]) + ser = Series(["x"]) ser.loc["td"] = pd.Timedelta("9 days") tm.assert_series_equal(ser, expected) assert isinstance(ser["td"], pd.Timedelta) @@ -771,7 +771,7 @@ def test_underlying_data_conversion(): # GH 3217 df = DataFrame(dict(a=[1, 3], b=[np.nan, 2])) df["c"] = np.nan - df["c"].update(pd.Series(["foo"], index=[0])) + df["c"].update(Series(["foo"], index=[0])) expected = DataFrame(dict(a=[1, 3], b=[np.nan, 2], c=["foo", np.nan])) tm.assert_frame_equal(df, expected) @@ -878,9 +878,9 @@ def test_pop(): def test_uint_drop(any_int_dtype): # see GH18311 # assigning series.loc[0] = 4 changed series.dtype to int - series = pd.Series([1, 2, 3], dtype=any_int_dtype) + series = Series([1, 2, 3], dtype=any_int_dtype) series.loc[0] = 4 - expected = pd.Series([4, 2, 3], dtype=any_int_dtype) + expected = Series([4, 2, 3], dtype=any_int_dtype) tm.assert_series_equal(series, expected) @@ -888,7 +888,7 @@ def test_getitem_unrecognized_scalar(): # GH#32684 a scalar key that is not recognized by lib.is_scalar # a series that might be produced via `frame.dtypes` - ser = pd.Series([1, 2], index=[np.dtype("O"), np.dtype("i8")]) + ser = Series([1, 2], index=[np.dtype("O"), np.dtype("i8")]) key = ser.index[1] @@ -949,7 +949,7 @@ def assert_slices_equivalent(l_slc, i_slc): def test_tuple_index(): # GH 35534 - Selecting values when a Series has an Index of tuples - s = pd.Series([1, 2], index=[("a",), ("b",)]) + s = Series([1, 2], index=[("a",), ("b",)]) assert s[("a",)] == 1 assert s[("b",)] == 2 s[("b",)] = 3 @@ -959,7 +959,7 @@ def test_tuple_index(): def test_frozenset_index(): # GH35747 - Selecting values when a Series has an Index of frozenset idx0, idx1 = frozenset("a"), frozenset("b") - s = pd.Series([1, 2], index=[idx0, idx1]) + s = Series([1, 2], index=[idx0, idx1]) assert s[idx0] == 1 assert s[idx1] == 2 s[idx1] = 3 diff --git a/pandas/tests/series/indexing/test_multiindex.py b/pandas/tests/series/indexing/test_multiindex.py index ed8bc52db7a9e..ff9db275ff2df 100644 --- a/pandas/tests/series/indexing/test_multiindex.py +++ b/pandas/tests/series/indexing/test_multiindex.py @@ -54,7 +54,7 @@ def test_nat_multi_index(ix_data, exp_data): def test_loc_getitem_multiindex_nonunique_len_zero(): # GH#13691 mi = pd.MultiIndex.from_product([[0], [1, 1]]) - ser = pd.Series(0, index=mi) + ser = Series(0, index=mi) res = ser.loc[[]] diff --git a/pandas/tests/series/indexing/test_where.py b/pandas/tests/series/indexing/test_where.py index cbb34d595eb9b..404136bdfa2db 100644 --- a/pandas/tests/series/indexing/test_where.py +++ b/pandas/tests/series/indexing/test_where.py @@ -349,7 +349,7 @@ def test_where_dups(): def test_where_numeric_with_string(): # GH 9280 - s = pd.Series([1, 2, 3]) + s = Series([1, 2, 3]) w = s.where(s > 1, "X") assert not is_integer(w[0]) @@ -425,15 +425,15 @@ def test_where_datetime_conversion(): def test_where_dt_tz_values(tz_naive_fixture): - ser1 = pd.Series( + ser1 = Series( pd.DatetimeIndex(["20150101", "20150102", "20150103"], tz=tz_naive_fixture) ) - ser2 = pd.Series( + ser2 = Series( pd.DatetimeIndex(["20160514", "20160515", "20160516"], tz=tz_naive_fixture) ) - mask = pd.Series([True, True, False]) + mask = Series([True, True, False]) result = ser1.where(mask, ser2) - exp = pd.Series( + exp = Series( pd.DatetimeIndex(["20150101", "20150102", "20160516"], tz=tz_naive_fixture) ) tm.assert_series_equal(exp, result) @@ -441,9 +441,9 @@ def test_where_dt_tz_values(tz_naive_fixture): def test_where_sparse(): # GH#17198 make sure we dont get an AttributeError for sp_index - ser = pd.Series(pd.arrays.SparseArray([1, 2])) + ser = Series(pd.arrays.SparseArray([1, 2])) result = ser.where(ser >= 2, 0) - expected = pd.Series(pd.arrays.SparseArray([0, 2])) + expected = Series(pd.arrays.SparseArray([0, 2])) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_align.py b/pandas/tests/series/methods/test_align.py index 974ba5d1e35a7..ef2b07d592b95 100644 --- a/pandas/tests/series/methods/test_align.py +++ b/pandas/tests/series/methods/test_align.py @@ -124,8 +124,8 @@ def test_align_multiindex(): [range(2), range(3), range(2)], names=("a", "b", "c") ) idx = pd.Index(range(2), name="b") - s1 = pd.Series(np.arange(12, dtype="int64"), index=midx) - s2 = pd.Series(np.arange(2, dtype="int64"), index=idx) + s1 = Series(np.arange(12, dtype="int64"), index=midx) + s2 = Series(np.arange(2, dtype="int64"), index=idx) # these must be the same results (but flipped) res1l, res1r = s1.align(s2, join="left") @@ -134,7 +134,7 @@ def test_align_multiindex(): expl = s1 tm.assert_series_equal(expl, res1l) tm.assert_series_equal(expl, res2r) - expr = pd.Series([0, 0, 1, 1, np.nan, np.nan] * 2, index=midx) + expr = Series([0, 0, 1, 1, np.nan, np.nan] * 2, index=midx) tm.assert_series_equal(expr, res1r) tm.assert_series_equal(expr, res2l) @@ -144,10 +144,10 @@ def test_align_multiindex(): exp_idx = pd.MultiIndex.from_product( [range(2), range(2), range(2)], names=("a", "b", "c") ) - expl = pd.Series([0, 1, 2, 3, 6, 7, 8, 9], index=exp_idx) + expl = Series([0, 1, 2, 3, 6, 7, 8, 9], index=exp_idx) tm.assert_series_equal(expl, res1l) tm.assert_series_equal(expl, res2r) - expr = pd.Series([0, 0, 1, 1] * 2, index=exp_idx) + expr = Series([0, 0, 1, 1] * 2, index=exp_idx) tm.assert_series_equal(expr, res1r) tm.assert_series_equal(expr, res2l) @@ -155,7 +155,7 @@ def test_align_multiindex(): @pytest.mark.parametrize("method", ["backfill", "bfill", "pad", "ffill", None]) def test_align_with_dataframe_method(method): # GH31788 - ser = pd.Series(range(3), index=range(3)) + ser = Series(range(3), index=range(3)) df = pd.DataFrame(0.0, index=range(3), columns=range(3)) result_ser, result_df = ser.align(df, method=method) diff --git a/pandas/tests/series/methods/test_append.py b/pandas/tests/series/methods/test_append.py index 82bde7c233626..e1d0bced55d98 100644 --- a/pandas/tests/series/methods/test_append.py +++ b/pandas/tests/series/methods/test_append.py @@ -29,14 +29,14 @@ def test_append_many(self, datetime_series): def test_append_duplicates(self): # GH 13677 - s1 = pd.Series([1, 2, 3]) - s2 = pd.Series([4, 5, 6]) - exp = pd.Series([1, 2, 3, 4, 5, 6], index=[0, 1, 2, 0, 1, 2]) + s1 = Series([1, 2, 3]) + s2 = Series([4, 5, 6]) + exp = Series([1, 2, 3, 4, 5, 6], index=[0, 1, 2, 0, 1, 2]) tm.assert_series_equal(s1.append(s2), exp) tm.assert_series_equal(pd.concat([s1, s2]), exp) # the result must have RangeIndex - exp = pd.Series([1, 2, 3, 4, 5, 6]) + exp = Series([1, 2, 3, 4, 5, 6]) tm.assert_series_equal( s1.append(s2, ignore_index=True), exp, check_index_type=True ) @@ -52,7 +52,7 @@ def test_append_duplicates(self): def test_append_tuples(self): # GH 28410 - s = pd.Series([1, 2, 3]) + s = Series([1, 2, 3]) list_input = [s, s] tuple_input = (s, s) diff --git a/pandas/tests/series/methods/test_clip.py b/pandas/tests/series/methods/test_clip.py index 37764d3b82c2d..5a5a397222b87 100644 --- a/pandas/tests/series/methods/test_clip.py +++ b/pandas/tests/series/methods/test_clip.py @@ -62,9 +62,9 @@ def test_clip_against_series(self): @pytest.mark.parametrize("upper", [[1, 2, 3], np.asarray([1, 2, 3])]) def test_clip_against_list_like(self, inplace, upper): # GH#15390 - original = pd.Series([5, 6, 7]) + original = Series([5, 6, 7]) result = original.clip(upper=upper, inplace=inplace) - expected = pd.Series([1, 2, 3]) + expected = Series([1, 2, 3]) if inplace: result = original diff --git a/pandas/tests/series/methods/test_combine_first.py b/pandas/tests/series/methods/test_combine_first.py index 1ee55fbe39513..2a02406f50750 100644 --- a/pandas/tests/series/methods/test_combine_first.py +++ b/pandas/tests/series/methods/test_combine_first.py @@ -76,11 +76,11 @@ def test_combine_first_dt64(self): tm.assert_series_equal(rs, xp) def test_combine_first_dt_tz_values(self, tz_naive_fixture): - ser1 = pd.Series( + ser1 = Series( pd.DatetimeIndex(["20150101", "20150102", "20150103"], tz=tz_naive_fixture), name="ser1", ) - ser2 = pd.Series( + ser2 = Series( pd.DatetimeIndex(["20160514", "20160515", "20160516"], tz=tz_naive_fixture), index=[2, 3, 4], name="ser2", @@ -90,5 +90,5 @@ def test_combine_first_dt_tz_values(self, tz_naive_fixture): ["20150101", "20150102", "20150103", "20160515", "20160516"], tz=tz_naive_fixture, ) - exp = pd.Series(exp_vals, name="ser1") + exp = Series(exp_vals, name="ser1") tm.assert_series_equal(exp, result) diff --git a/pandas/tests/series/methods/test_count.py b/pandas/tests/series/methods/test_count.py index 19290b6a5c23f..3c5957706b144 100644 --- a/pandas/tests/series/methods/test_count.py +++ b/pandas/tests/series/methods/test_count.py @@ -8,7 +8,7 @@ class TestSeriesCount: def test_count_level_without_multiindex(self): - ser = pd.Series(range(3)) + ser = Series(range(3)) msg = "Series.count level is only valid with a MultiIndex" with pytest.raises(ValueError, match=msg): @@ -33,7 +33,7 @@ def test_count(self, datetime_series): # GH#29478 with pd.option_context("use_inf_as_na", True): - assert pd.Series([pd.Timestamp("1990/1/1")]).count() == 1 + assert Series([pd.Timestamp("1990/1/1")]).count() == 1 def test_count_categorical(self): diff --git a/pandas/tests/series/methods/test_cov_corr.py b/pandas/tests/series/methods/test_cov_corr.py index 282f499506aae..f01ed73c0165f 100644 --- a/pandas/tests/series/methods/test_cov_corr.py +++ b/pandas/tests/series/methods/test_cov_corr.py @@ -135,8 +135,8 @@ def test_corr_rank(self): def test_corr_invalid_method(self): # GH PR #22298 - s1 = pd.Series(np.random.randn(10)) - s2 = pd.Series(np.random.randn(10)) + s1 = Series(np.random.randn(10)) + s2 = Series(np.random.randn(10)) msg = "method must be either 'pearson', 'spearman', 'kendall', or a callable, " with pytest.raises(ValueError, match=msg): s1.corr(s2, method="____") diff --git a/pandas/tests/series/methods/test_drop.py b/pandas/tests/series/methods/test_drop.py index 197fe9ff68df2..7ded8ac902d78 100644 --- a/pandas/tests/series/methods/test_drop.py +++ b/pandas/tests/series/methods/test_drop.py @@ -1,6 +1,5 @@ import pytest -import pandas as pd from pandas import Series import pandas._testing as tm @@ -66,8 +65,8 @@ def test_drop_with_ignore_errors(): def test_drop_empty_list(index, drop_labels): # GH 21494 expected_index = [i for i in index if i not in drop_labels] - series = pd.Series(index=index, dtype=object).drop(drop_labels) - expected = pd.Series(index=expected_index, dtype=object) + series = Series(index=index, dtype=object).drop(drop_labels) + expected = Series(index=expected_index, dtype=object) tm.assert_series_equal(series, expected) @@ -82,6 +81,6 @@ def test_drop_empty_list(index, drop_labels): def test_drop_non_empty_list(data, index, drop_labels): # GH 21494 and GH 16877 dtype = object if data is None else None - ser = pd.Series(data=data, index=index, dtype=dtype) + ser = Series(data=data, index=index, dtype=dtype) with pytest.raises(KeyError, match="not found in axis"): ser.drop(drop_labels) diff --git a/pandas/tests/series/methods/test_interpolate.py b/pandas/tests/series/methods/test_interpolate.py index 9fc468221ee2d..1b05f72f5cf4d 100644 --- a/pandas/tests/series/methods/test_interpolate.py +++ b/pandas/tests/series/methods/test_interpolate.py @@ -314,14 +314,14 @@ def test_interp_limit(self): @pytest.mark.parametrize("limit", [-1, 0]) def test_interpolate_invalid_nonpositive_limit(self, nontemporal_method, limit): # GH 9217: make sure limit is greater than zero. - s = pd.Series([1, 2, np.nan, 4]) + s = Series([1, 2, np.nan, 4]) method, kwargs = nontemporal_method with pytest.raises(ValueError, match="Limit must be greater than 0"): s.interpolate(limit=limit, method=method, **kwargs) def test_interpolate_invalid_float_limit(self, nontemporal_method): # GH 9217: make sure limit is an integer. - s = pd.Series([1, 2, np.nan, 4]) + s = Series([1, 2, np.nan, 4]) method, kwargs = nontemporal_method limit = 2.0 with pytest.raises(ValueError, match="Limit must be an integer"): @@ -561,17 +561,17 @@ def test_interp_datetime64(self, method, tz_naive_fixture): def test_interp_pad_datetime64tz_values(self): # GH#27628 missing.interpolate_2d should handle datetimetz values dti = pd.date_range("2015-04-05", periods=3, tz="US/Central") - ser = pd.Series(dti) + ser = Series(dti) ser[1] = pd.NaT result = ser.interpolate(method="pad") - expected = pd.Series(dti) + expected = Series(dti) expected[1] = expected[0] tm.assert_series_equal(result, expected) def test_interp_limit_no_nans(self): # GH 7173 - s = pd.Series([1.0, 2.0, 3.0]) + s = Series([1.0, 2.0, 3.0]) result = s.interpolate(limit=1) expected = s tm.assert_series_equal(result, expected) @@ -654,13 +654,13 @@ def test_series_interpolate_method_values(self): def test_series_interpolate_intraday(self): # #1698 index = pd.date_range("1/1/2012", periods=4, freq="12D") - ts = pd.Series([0, 12, 24, 36], index) + ts = Series([0, 12, 24, 36], index) new_index = index.append(index + pd.DateOffset(days=1)).sort_values() exp = ts.reindex(new_index).interpolate(method="time") index = pd.date_range("1/1/2012", periods=4, freq="12H") - ts = pd.Series([0, 12, 24, 36], index) + ts = Series([0, 12, 24, 36], index) new_index = index.append(index + pd.DateOffset(hours=1)).sort_values() result = ts.reindex(new_index).interpolate(method="time") @@ -684,7 +684,7 @@ def test_interp_non_timedelta_index(self, interp_methods_ind, ind): if method == "linear": result = df[0].interpolate(**kwargs) - expected = pd.Series([0.0, 1.0, 2.0, 3.0], name=0, index=ind) + expected = Series([0.0, 1.0, 2.0, 3.0], name=0, index=ind) tm.assert_series_equal(result, expected) else: expected_error = ( @@ -712,7 +712,7 @@ def test_interpolate_timedelta_index(self, interp_methods_ind): if method in {"linear", "pchip"}: result = df[0].interpolate(method=method, **kwargs) - expected = pd.Series([0.0, 1.0, 2.0, 3.0], name=0, index=ind) + expected = Series([0.0, 1.0, 2.0, 3.0], name=0, index=ind) tm.assert_series_equal(result, expected) else: pytest.skip( @@ -725,7 +725,7 @@ def test_interpolate_timedelta_index(self, interp_methods_ind): ) def test_interpolate_unsorted_index(self, ascending, expected_values): # GH 21037 - ts = pd.Series(data=[10, 9, np.nan, 2, 1], index=[10, 9, 3, 2, 1]) + ts = Series(data=[10, 9, np.nan, 2, 1], index=[10, 9, 3, 2, 1]) result = ts.sort_index(ascending=ascending).interpolate(method="index") - expected = pd.Series(data=expected_values, index=expected_values, dtype=float) + expected = Series(data=expected_values, index=expected_values, dtype=float) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_quantile.py b/pandas/tests/series/methods/test_quantile.py index 79f50afca658f..964d62602edaa 100644 --- a/pandas/tests/series/methods/test_quantile.py +++ b/pandas/tests/series/methods/test_quantile.py @@ -45,7 +45,7 @@ def test_quantile_multi(self, datetime_series): qs = [0.1, 0.9] result = datetime_series.quantile(qs) - expected = pd.Series( + expected = Series( [ np.percentile(datetime_series.dropna(), 10), np.percentile(datetime_series.dropna(), 90), @@ -66,7 +66,7 @@ def test_quantile_multi(self, datetime_series): tm.assert_series_equal(result, expected) result = datetime_series.quantile([]) - expected = pd.Series( + expected = Series( [], name=datetime_series.name, index=Index([], dtype=float), dtype="float64" ) tm.assert_series_equal(result, expected) @@ -87,18 +87,18 @@ def test_quantile_interpolation_dtype(self): # GH #10174 # interpolation = linear (default case) - q = pd.Series([1, 3, 4]).quantile(0.5, interpolation="lower") + q = Series([1, 3, 4]).quantile(0.5, interpolation="lower") assert q == np.percentile(np.array([1, 3, 4]), 50) assert is_integer(q) - q = pd.Series([1, 3, 4]).quantile(0.5, interpolation="higher") + q = Series([1, 3, 4]).quantile(0.5, interpolation="higher") assert q == np.percentile(np.array([1, 3, 4]), 50) assert is_integer(q) def test_quantile_nan(self): # GH 13098 - s = pd.Series([1, 2, 3, 4, np.nan]) + s = Series([1, 2, 3, 4, np.nan]) result = s.quantile(0.5) expected = 2.5 assert result == expected @@ -112,10 +112,10 @@ def test_quantile_nan(self): assert np.isnan(res) res = s.quantile([0.5]) - tm.assert_series_equal(res, pd.Series([np.nan], index=[0.5])) + tm.assert_series_equal(res, Series([np.nan], index=[0.5])) res = s.quantile([0.2, 0.3]) - tm.assert_series_equal(res, pd.Series([np.nan, np.nan], index=[0.2, 0.3])) + tm.assert_series_equal(res, Series([np.nan, np.nan], index=[0.2, 0.3])) @pytest.mark.parametrize( "case", @@ -153,12 +153,12 @@ def test_quantile_nan(self): ], ) def test_quantile_box(self, case): - s = pd.Series(case, name="XXX") + s = Series(case, name="XXX") res = s.quantile(0.5) assert res == case[1] res = s.quantile([0.5]) - exp = pd.Series([case[1]], index=[0.5], name="XXX") + exp = Series([case[1]], index=[0.5], name="XXX") tm.assert_series_equal(res, exp) def test_datetime_timedelta_quantiles(self): @@ -171,16 +171,16 @@ def test_quantile_nat(self): assert res is pd.NaT res = Series([pd.NaT, pd.NaT]).quantile([0.5]) - tm.assert_series_equal(res, pd.Series([pd.NaT], index=[0.5])) + tm.assert_series_equal(res, Series([pd.NaT], index=[0.5])) @pytest.mark.parametrize( "values, dtype", [([0, 0, 0, 1, 2, 3], "Sparse[int]"), ([0.0, None, 1.0, 2.0], "Sparse[float]")], ) def test_quantile_sparse(self, values, dtype): - ser = pd.Series(values, dtype=dtype) + ser = Series(values, dtype=dtype) result = ser.quantile([0.5]) - expected = pd.Series(np.asarray(ser)).quantile([0.5]) + expected = Series(np.asarray(ser)).quantile([0.5]) tm.assert_series_equal(result, expected) def test_quantile_empty(self): diff --git a/pandas/tests/series/methods/test_shift.py b/pandas/tests/series/methods/test_shift.py index da6407c73104c..20bb3e008c792 100644 --- a/pandas/tests/series/methods/test_shift.py +++ b/pandas/tests/series/methods/test_shift.py @@ -135,14 +135,14 @@ def test_shift_fill_value(self): result = ts.shift(2, fill_value=0.0) tm.assert_series_equal(result, exp) - ts = pd.Series([1, 2, 3]) + ts = Series([1, 2, 3]) res = ts.shift(2, fill_value=0) assert res.dtype == ts.dtype def test_shift_categorical_fill_value(self): - ts = pd.Series(["a", "b", "c", "d"], dtype="category") + ts = Series(["a", "b", "c", "d"], dtype="category") res = ts.shift(1, fill_value="a") - expected = pd.Series( + expected = Series( pd.Categorical( ["a", "a", "b", "c"], categories=["a", "b", "c", "d"], ordered=False ) @@ -302,7 +302,7 @@ def test_shift_object_non_scalar_fill(self): def test_shift_categorical(self): # GH#9416 - s = pd.Series(["a", "b", "c", "d"], dtype="category") + s = Series(["a", "b", "c", "d"], dtype="category") tm.assert_series_equal(s.iloc[:-1], s.shift(1).shift(-1).dropna()) @@ -321,25 +321,25 @@ def test_shift_categorical(self): def test_shift_dt64values_int_fill_deprecated(self): # GH#31971 - ser = pd.Series([pd.Timestamp("2020-01-01"), pd.Timestamp("2020-01-02")]) + ser = Series([pd.Timestamp("2020-01-01"), pd.Timestamp("2020-01-02")]) with tm.assert_produces_warning(FutureWarning): result = ser.shift(1, fill_value=0) - expected = pd.Series([pd.Timestamp(0), ser[0]]) + expected = Series([pd.Timestamp(0), ser[0]]) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("periods", [1, 2, 3, 4]) def test_shift_preserve_freqstr(self, periods): # GH#21275 - ser = pd.Series( + ser = Series( range(periods), index=pd.date_range("2016-1-1 00:00:00", periods=periods, freq="H"), ) result = ser.shift(1, "2H") - expected = pd.Series( + expected = Series( range(periods), index=pd.date_range("2016-1-1 02:00:00", periods=periods, freq="H"), ) @@ -353,7 +353,7 @@ def test_shift_non_writable_array(self, input_data, output_data): # GH21049 Verify whether non writable numpy array is shiftable input_data.setflags(write=False) - result = pd.Series(input_data).shift(1) - expected = pd.Series(output_data, dtype="float64") + result = Series(input_data).shift(1) + expected = Series(output_data, dtype="float64") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/methods/test_truncate.py b/pandas/tests/series/methods/test_truncate.py index 858b1d6b4df8c..b03f516eeffc5 100644 --- a/pandas/tests/series/methods/test_truncate.py +++ b/pandas/tests/series/methods/test_truncate.py @@ -67,14 +67,14 @@ def test_truncate(self, datetime_series): def test_truncate_nonsortedindex(self): # GH#17935 - s = pd.Series(["a", "b", "c", "d", "e"], index=[5, 3, 2, 9, 0]) + s = Series(["a", "b", "c", "d", "e"], index=[5, 3, 2, 9, 0]) msg = "truncate requires a sorted index" with pytest.raises(ValueError, match=msg): s.truncate(before=3, after=9) rng = pd.date_range("2011-01-01", "2012-01-01", freq="W") - ts = pd.Series(np.random.randn(len(rng)), index=rng) + ts = Series(np.random.randn(len(rng)), index=rng) msg = "truncate requires a sorted index" with pytest.raises(ValueError, match=msg): @@ -92,7 +92,7 @@ def test_truncate_decreasing_index(self, before, after, indices, klass): before = pd.Timestamp(before) if before is not None else None after = pd.Timestamp(after) if after is not None else None indices = [pd.Timestamp(i) for i in indices] - values = pd.Series(range(len(idx)), index=idx) + values = Series(range(len(idx)), index=idx) result = values.truncate(before=before, after=after) expected = values.loc[indices] tm.assert_series_equal(result, expected) @@ -116,27 +116,27 @@ def test_truncate_periodindex(self): idx1 = pd.PeriodIndex( [pd.Period("2017-09-02"), pd.Period("2017-09-02"), pd.Period("2017-09-03")] ) - series1 = pd.Series([1, 2, 3], index=idx1) + series1 = Series([1, 2, 3], index=idx1) result1 = series1.truncate(after="2017-09-02") expected_idx1 = pd.PeriodIndex( [pd.Period("2017-09-02"), pd.Period("2017-09-02")] ) - tm.assert_series_equal(result1, pd.Series([1, 2], index=expected_idx1)) + tm.assert_series_equal(result1, Series([1, 2], index=expected_idx1)) idx2 = pd.PeriodIndex( [pd.Period("2017-09-03"), pd.Period("2017-09-02"), pd.Period("2017-09-03")] ) - series2 = pd.Series([1, 2, 3], index=idx2) + series2 = Series([1, 2, 3], index=idx2) result2 = series2.sort_index().truncate(after="2017-09-02") expected_idx2 = pd.PeriodIndex([pd.Period("2017-09-02")]) - tm.assert_series_equal(result2, pd.Series([2], index=expected_idx2)) + tm.assert_series_equal(result2, Series([2], index=expected_idx2)) def test_truncate_multiindex(self): # GH 34564 mi = pd.MultiIndex.from_product([[1, 2, 3, 4], ["A", "B"]], names=["L1", "L2"]) - s1 = pd.Series(range(mi.shape[0]), index=mi, name="col") + s1 = Series(range(mi.shape[0]), index=mi, name="col") result = s1.truncate(before=2, after=3) df = pd.DataFrame.from_dict( @@ -150,7 +150,7 @@ def test_truncate_multiindex(self): def test_truncate_one_element_series(self): # GH 35544 - series = pd.Series([0.1], index=pd.DatetimeIndex(["2020-08-04"])) + series = Series([0.1], index=pd.DatetimeIndex(["2020-08-04"])) before = pd.Timestamp("2020-08-02") after = pd.Timestamp("2020-08-04") diff --git a/pandas/tests/series/methods/test_unstack.py b/pandas/tests/series/methods/test_unstack.py index d651315d64561..d8099e84a324d 100644 --- a/pandas/tests/series/methods/test_unstack.py +++ b/pandas/tests/series/methods/test_unstack.py @@ -41,7 +41,7 @@ def test_unstack(): # GH5873 idx = pd.MultiIndex.from_arrays([[101, 102], [3.5, np.nan]]) - ts = pd.Series([1, 2], index=idx) + ts = Series([1, 2], index=idx) left = ts.unstack() right = DataFrame( [[np.nan, 1], [2, np.nan]], index=[101, 102], columns=[np.nan, 3.5] @@ -55,7 +55,7 @@ def test_unstack(): [1, 2, 1, 1, np.nan], ] ) - ts = pd.Series([1.0, 1.1, 1.2, 1.3, 1.4], index=idx) + ts = Series([1.0, 1.1, 1.2, 1.3, 1.4], index=idx) right = DataFrame( [[1.0, 1.3], [1.1, np.nan], [np.nan, 1.4], [1.2, np.nan]], columns=["cat", "dog"], @@ -70,7 +70,7 @@ def test_unstack_tuplename_in_multiindex(): idx = pd.MultiIndex.from_product( [["a", "b", "c"], [1, 2, 3]], names=[("A", "a"), ("B", "b")] ) - ser = pd.Series(1, index=idx) + ser = Series(1, index=idx) result = ser.unstack(("A", "a")) expected = pd.DataFrame( @@ -109,7 +109,7 @@ def test_unstack_mixed_type_name_in_multiindex( idx = pd.MultiIndex.from_product( [["a", "b"], [1, 2], [3, 4]], names=[("A", "a"), "B", "C"] ) - ser = pd.Series(1, index=idx) + ser = Series(1, index=idx) result = ser.unstack(unstack_idx) expected = pd.DataFrame( @@ -121,7 +121,7 @@ def test_unstack_mixed_type_name_in_multiindex( def test_unstack_multi_index_categorical_values(): mi = tm.makeTimeDataFrame().stack().index.rename(["major", "minor"]) - ser = pd.Series(["foo"] * len(mi), index=mi, name="category", dtype="category") + ser = Series(["foo"] * len(mi), index=mi, name="category", dtype="category") result = ser.unstack() diff --git a/pandas/tests/series/methods/test_value_counts.py b/pandas/tests/series/methods/test_value_counts.py index f97362ce9c2a9..37da31fb2329a 100644 --- a/pandas/tests/series/methods/test_value_counts.py +++ b/pandas/tests/series/methods/test_value_counts.py @@ -21,16 +21,16 @@ def test_value_counts_datetime(self): exp_idx = pd.DatetimeIndex( ["2011-01-01 09:00", "2011-01-01 11:00", "2011-01-01 10:00"] ) - exp = pd.Series([3, 2, 1], index=exp_idx, name="xxx") + exp = Series([3, 2, 1], index=exp_idx, name="xxx") - ser = pd.Series(values, name="xxx") + ser = Series(values, name="xxx") tm.assert_series_equal(ser.value_counts(), exp) # check DatetimeIndex outputs the same result idx = pd.DatetimeIndex(values, name="xxx") tm.assert_series_equal(idx.value_counts(), exp) # normalize - exp = pd.Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") + exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") tm.assert_series_equal(ser.value_counts(normalize=True), exp) tm.assert_series_equal(idx.value_counts(normalize=True), exp) @@ -48,14 +48,14 @@ def test_value_counts_datetime_tz(self): ["2011-01-01 09:00", "2011-01-01 11:00", "2011-01-01 10:00"], tz="US/Eastern", ) - exp = pd.Series([3, 2, 1], index=exp_idx, name="xxx") + exp = Series([3, 2, 1], index=exp_idx, name="xxx") - ser = pd.Series(values, name="xxx") + ser = Series(values, name="xxx") tm.assert_series_equal(ser.value_counts(), exp) idx = pd.DatetimeIndex(values, name="xxx") tm.assert_series_equal(idx.value_counts(), exp) - exp = pd.Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") + exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") tm.assert_series_equal(ser.value_counts(normalize=True), exp) tm.assert_series_equal(idx.value_counts(normalize=True), exp) @@ -70,16 +70,16 @@ def test_value_counts_period(self): ] exp_idx = pd.PeriodIndex(["2011-01", "2011-03", "2011-02"], freq="M") - exp = pd.Series([3, 2, 1], index=exp_idx, name="xxx") + exp = Series([3, 2, 1], index=exp_idx, name="xxx") - ser = pd.Series(values, name="xxx") + ser = Series(values, name="xxx") tm.assert_series_equal(ser.value_counts(), exp) # check DatetimeIndex outputs the same result idx = pd.PeriodIndex(values, name="xxx") tm.assert_series_equal(idx.value_counts(), exp) # normalize - exp = pd.Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") + exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") tm.assert_series_equal(ser.value_counts(normalize=True), exp) tm.assert_series_equal(idx.value_counts(normalize=True), exp) @@ -88,16 +88,16 @@ def test_value_counts_categorical_ordered(self): values = pd.Categorical([1, 2, 3, 1, 1, 3], ordered=True) exp_idx = pd.CategoricalIndex([1, 3, 2], categories=[1, 2, 3], ordered=True) - exp = pd.Series([3, 2, 1], index=exp_idx, name="xxx") + exp = Series([3, 2, 1], index=exp_idx, name="xxx") - ser = pd.Series(values, name="xxx") + ser = Series(values, name="xxx") tm.assert_series_equal(ser.value_counts(), exp) # check CategoricalIndex outputs the same result idx = pd.CategoricalIndex(values, name="xxx") tm.assert_series_equal(idx.value_counts(), exp) # normalize - exp = pd.Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") + exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") tm.assert_series_equal(ser.value_counts(normalize=True), exp) tm.assert_series_equal(idx.value_counts(normalize=True), exp) @@ -105,16 +105,16 @@ def test_value_counts_categorical_not_ordered(self): values = pd.Categorical([1, 2, 3, 1, 1, 3], ordered=False) exp_idx = pd.CategoricalIndex([1, 3, 2], categories=[1, 2, 3], ordered=False) - exp = pd.Series([3, 2, 1], index=exp_idx, name="xxx") + exp = Series([3, 2, 1], index=exp_idx, name="xxx") - ser = pd.Series(values, name="xxx") + ser = Series(values, name="xxx") tm.assert_series_equal(ser.value_counts(), exp) # check CategoricalIndex outputs the same result idx = pd.CategoricalIndex(values, name="xxx") tm.assert_series_equal(idx.value_counts(), exp) # normalize - exp = pd.Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") + exp = Series(np.array([3.0, 2.0, 1]) / 6.0, index=exp_idx, name="xxx") tm.assert_series_equal(ser.value_counts(normalize=True), exp) tm.assert_series_equal(idx.value_counts(normalize=True), exp) @@ -183,19 +183,19 @@ def test_value_counts_categorical_with_nan(self): "ser, dropna, exp", [ ( - pd.Series([False, True, True, pd.NA]), + Series([False, True, True, pd.NA]), False, - pd.Series([2, 1, 1], index=[True, False, pd.NA]), + Series([2, 1, 1], index=[True, False, pd.NA]), ), ( - pd.Series([False, True, True, pd.NA]), + Series([False, True, True, pd.NA]), True, - pd.Series([2, 1], index=[True, False]), + Series([2, 1], index=[True, False]), ), ( - pd.Series(range(3), index=[True, False, np.nan]).index, + Series(range(3), index=[True, False, np.nan]).index, False, - pd.Series([1, 1, 1], index=[True, False, pd.NA]), + Series([1, 1, 1], index=[True, False, pd.NA]), ), ], ) diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index d92edb6fe149a..92cd1e546b54d 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -179,7 +179,7 @@ def test_constructor_dict_timedelta_index(self): tm.assert_series_equal(result, expected) def test_sparse_accessor_updates_on_inplace(self): - s = pd.Series([1, 1, 2, 3], dtype="Sparse[int]") + s = Series([1, 1, 2, 3], dtype="Sparse[int]") return_value = s.drop([0, 1], inplace=True) assert return_value is None assert s.sparse.density == 1.0 @@ -257,7 +257,7 @@ def get_dir(s): ) def test_index_tab_completion(self, index): # dir contains string-like values of the Index. - s = pd.Series(index=index, dtype=object) + s = Series(index=index, dtype=object) dir_s = dir(s) for i, x in enumerate(s.index.unique(level=0)): if i < 100: @@ -460,7 +460,7 @@ def f(x): tm.assert_almost_equal(s.ravel(order="F"), s.values.ravel(order="F")) def test_str_accessor_updates_on_inplace(self): - s = pd.Series(list("abc")) + s = Series(list("abc")) return_value = s.drop([0], inplace=True) assert return_value is None assert len(s.str.lower()) == 2 @@ -479,11 +479,11 @@ def test_str_attribute(self): s.str.repeat(2) def test_empty_method(self): - s_empty = pd.Series(dtype=object) + s_empty = Series(dtype=object) assert s_empty.empty - s2 = pd.Series(index=[1], dtype=object) - for full_series in [pd.Series([1]), s2]: + s2 = Series(index=[1], dtype=object) + for full_series in [Series([1]), s2]: assert not full_series.empty @async_mark() @@ -493,7 +493,7 @@ async def test_tab_complete_warning(self, ip): pytest.importorskip("IPython", minversion="6.0.0") from IPython.core.completer import provisionalcompleter - code = "import pandas as pd; s = pd.Series(dtype=object)" + code = "import pandas as pd; s = Series(dtype=object)" await ip.run_code(code) # TODO: remove it when Ipython updates @@ -518,7 +518,7 @@ def test_integer_series_size(self): assert s.size == 9 def test_attrs(self): - s = pd.Series([0, 1], name="abc") + s = Series([0, 1], name="abc") assert s.attrs == {} s.attrs["version"] = 1 result = s + 1 @@ -526,7 +526,7 @@ def test_attrs(self): @pytest.mark.parametrize("allows_duplicate_labels", [True, False, None]) def test_set_flags(self, allows_duplicate_labels): - df = pd.Series([1, 2]) + df = Series([1, 2]) result = df.set_flags(allows_duplicate_labels=allows_duplicate_labels) if allows_duplicate_labels is None: # We don't update when it's not provided diff --git a/pandas/tests/series/test_arithmetic.py b/pandas/tests/series/test_arithmetic.py index 09181201beee4..00e6fb01da424 100644 --- a/pandas/tests/series/test_arithmetic.py +++ b/pandas/tests/series/test_arithmetic.py @@ -191,7 +191,7 @@ def test_add_with_duplicate_index(self): s1 = Series([1, 2], index=[1, 1]) s2 = Series([10, 10], index=[1, 2]) result = s1 + s2 - expected = pd.Series([11, 12, np.nan], index=[1, 1, 2]) + expected = Series([11, 12, np.nan], index=[1, 1, 2]) tm.assert_series_equal(result, expected) def test_add_na_handling(self): @@ -258,8 +258,8 @@ def test_alignment_doesnt_change_tz(self): # GH#33671 dti = pd.date_range("2016-01-01", periods=10, tz="CET") dti_utc = dti.tz_convert("UTC") - ser = pd.Series(10, index=dti) - ser_utc = pd.Series(10, index=dti_utc) + ser = Series(10, index=dti) + ser_utc = Series(10, index=dti_utc) # we don't care about the result, just that original indexes are unchanged ser * ser_utc @@ -276,16 +276,16 @@ class TestSeriesFlexComparison: @pytest.mark.parametrize("axis", [0, None, "index"]) def test_comparison_flex_basic(self, axis, all_compare_operators): op = all_compare_operators.strip("__") - left = pd.Series(np.random.randn(10)) - right = pd.Series(np.random.randn(10)) + left = Series(np.random.randn(10)) + right = Series(np.random.randn(10)) result = getattr(left, op)(right, axis=axis) expected = getattr(operator, op)(left, right) tm.assert_series_equal(result, expected) def test_comparison_bad_axis(self, all_compare_operators): op = all_compare_operators.strip("__") - left = pd.Series(np.random.randn(10)) - right = pd.Series(np.random.randn(10)) + left = Series(np.random.randn(10)) + right = Series(np.random.randn(10)) msg = "No axis named 1 for object type" with pytest.raises(ValueError, match=msg): @@ -306,7 +306,7 @@ def test_comparison_flex_alignment(self, values, op): left = Series([1, 3, 2], index=list("abc")) right = Series([2, 2, 2], index=list("bcd")) result = getattr(left, op)(right) - expected = pd.Series(values, index=list("abcd")) + expected = Series(values, index=list("abcd")) tm.assert_series_equal(result, expected) @pytest.mark.parametrize( @@ -324,7 +324,7 @@ def test_comparison_flex_alignment_fill(self, values, op, fill_value): left = Series([1, 3, 2], index=list("abc")) right = Series([2, 2, 2], index=list("bcd")) result = getattr(left, op)(right, fill_value=fill_value) - expected = pd.Series(values, index=list("abcd")) + expected = Series(values, index=list("abcd")) tm.assert_series_equal(result, expected) @@ -585,12 +585,12 @@ def test_ne(self): "left, right", [ ( - pd.Series([1, 2, 3], index=list("ABC"), name="x"), - pd.Series([2, 2, 2], index=list("ABD"), name="x"), + Series([1, 2, 3], index=list("ABC"), name="x"), + Series([2, 2, 2], index=list("ABD"), name="x"), ), ( - pd.Series([1, 2, 3], index=list("ABC"), name="x"), - pd.Series([2, 2, 2, 2], index=list("ABCD"), name="x"), + Series([1, 2, 3], index=list("ABC"), name="x"), + Series([2, 2, 2, 2], index=list("ABCD"), name="x"), ), ], ) @@ -694,10 +694,10 @@ def test_series_add_aware_naive_raises(self): def test_datetime_understood(self): # Ensures it doesn't fail to create the right series # reported in issue#16726 - series = pd.Series(pd.date_range("2012-01-01", periods=3)) + series = Series(pd.date_range("2012-01-01", periods=3)) offset = pd.offsets.DateOffset(days=6) result = series - offset - expected = pd.Series(pd.to_datetime(["2011-12-26", "2011-12-27", "2011-12-28"])) + expected = Series(pd.to_datetime(["2011-12-26", "2011-12-27", "2011-12-28"])) tm.assert_series_equal(result, expected) @@ -718,8 +718,8 @@ def test_series_ops_name_retention(flex, box, names, all_binary_operators): if op is ops.rfloordiv and box in [list, tuple]: pytest.xfail("op fails because of inconsistent ndarray-wrapping GH#28759") - left = pd.Series(range(10), name=names[0]) - right = pd.Series(range(10), name=names[1]) + left = Series(range(10), name=names[0]) + right = Series(range(10), name=names[1]) right = box(right) if flex: diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index a950ca78fc742..491b3a62b7d73 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -179,24 +179,24 @@ def test_constructor_nan(self, input_arg): @pytest.mark.parametrize("index", [None, pd.Index([])]) def test_constructor_dtype_only(self, dtype, index): # GH-20865 - result = pd.Series(dtype=dtype, index=index) + result = Series(dtype=dtype, index=index) assert result.dtype == dtype assert len(result) == 0 def test_constructor_no_data_index_order(self): with tm.assert_produces_warning(DeprecationWarning, check_stacklevel=False): - result = pd.Series(index=["b", "a", "c"]) + result = Series(index=["b", "a", "c"]) assert result.index.tolist() == ["b", "a", "c"] def test_constructor_no_data_string_type(self): # GH 22477 - result = pd.Series(index=[1], dtype=str) + result = Series(index=[1], dtype=str) assert np.isnan(result.iloc[0]) @pytest.mark.parametrize("item", ["entry", "ѐ", 13]) def test_constructor_string_element_string_type(self, item): # GH 22477 - result = pd.Series(item, index=[1], dtype=str) + result = Series(item, index=[1], dtype=str) assert result.iloc[0] == str(item) def test_constructor_dtype_str_na_values(self, string_dtype): @@ -313,7 +313,7 @@ def test_constructor_categorical(self): # can cast to a new dtype result = Series(pd.Categorical([1, 2, 3]), dtype="int64") - expected = pd.Series([1, 2, 3], dtype="int64") + expected = Series([1, 2, 3], dtype="int64") tm.assert_series_equal(result, expected) # GH12574 @@ -379,14 +379,14 @@ def test_constructor_categorical_with_coercion(self): assert result == expected def test_constructor_categorical_dtype(self): - result = pd.Series( + result = Series( ["a", "b"], dtype=CategoricalDtype(["a", "b", "c"], ordered=True) ) assert is_categorical_dtype(result.dtype) is True tm.assert_index_equal(result.cat.categories, pd.Index(["a", "b", "c"])) assert result.cat.ordered - result = pd.Series(["a", "b"], dtype=CategoricalDtype(["b", "a"])) + result = Series(["a", "b"], dtype=CategoricalDtype(["b", "a"])) assert is_categorical_dtype(result.dtype) tm.assert_index_equal(result.cat.categories, pd.Index(["b", "a"])) assert result.cat.ordered is False @@ -449,8 +449,8 @@ def test_categorical_sideeffects_free(self): tm.assert_numpy_array_equal(cat.__array__(), exp_s2) def test_unordered_compare_equal(self): - left = pd.Series(["a", "b", "c"], dtype=CategoricalDtype(["a", "b"])) - right = pd.Series(pd.Categorical(["a", "b", np.nan], categories=["a", "b"])) + left = Series(["a", "b", "c"], dtype=CategoricalDtype(["a", "b"])) + right = Series(pd.Categorical(["a", "b", np.nan], categories=["a", "b"])) tm.assert_series_equal(left, right) def test_constructor_maskedarray(self): @@ -533,8 +533,8 @@ def test_constructor_maskedarray(self): def test_constructor_maskedarray_hardened(self): # Check numpy masked arrays with hard masks -- from GH24574 data = ma.masked_all((3,), dtype=float).harden_mask() - result = pd.Series(data) - expected = pd.Series([np.nan, np.nan, np.nan]) + result = Series(data) + expected = Series([np.nan, np.nan, np.nan]) tm.assert_series_equal(result, expected) def test_series_ctor_plus_datetimeindex(self): @@ -601,7 +601,7 @@ def test_constructor_copy(self): # test dtype parameter has no side effects on copy=True for data in [[1.0], np.array([1.0])]: x = Series(data) - y = pd.Series(x, copy=True, dtype=float) + y = Series(x, copy=True, dtype=float) # copy=True maintains original data in Series tm.assert_series_equal(x, y) @@ -628,7 +628,7 @@ def test_constructor_copy(self): def test_constructor_limit_copies(self, index): # GH 17449 # limit copies of input - s = pd.Series(index) + s = Series(index) # we make 1 copy; this is just a smoke test here assert s._mgr.blocks[0].values is not index @@ -995,8 +995,8 @@ def test_construction_interval(self, interval_constructor): def test_constructor_infer_interval(self, data_constructor): # GH 23563: consistent closed results in interval dtype data = [pd.Interval(0, 1), pd.Interval(0, 2), None] - result = pd.Series(data_constructor(data)) - expected = pd.Series(IntervalArray(data)) + result = Series(data_constructor(data)) + expected = Series(IntervalArray(data)) assert result.dtype == "interval[float64]" tm.assert_series_equal(result, expected) @@ -1030,14 +1030,14 @@ def test_construction_consistency(self): ) def test_constructor_infer_period(self, data_constructor): data = [pd.Period("2000", "D"), pd.Period("2001", "D"), None] - result = pd.Series(data_constructor(data)) - expected = pd.Series(period_array(data)) + result = Series(data_constructor(data)) + expected = Series(period_array(data)) tm.assert_series_equal(result, expected) assert result.dtype == "Period[D]" def test_constructor_period_incompatible_frequency(self): data = [pd.Period("2000", "D"), pd.Period("2001", "A")] - result = pd.Series(data) + result = Series(data) assert result.dtype == object assert result.tolist() == data @@ -1473,7 +1473,7 @@ def test_constructor_datetime64(self): def test_constructor_datetimelike_scalar_to_string_dtype(self): # https://github.com/pandas-dev/pandas/pull/33846 result = Series("M", index=[1, 2, 3], dtype="string") - expected = pd.Series(["M", "M", "M"], index=[1, 2, 3], dtype="string") + expected = Series(["M", "M", "M"], index=[1, 2, 3], dtype="string") tm.assert_series_equal(result, expected) @pytest.mark.parametrize( @@ -1486,9 +1486,9 @@ def test_constructor_datetimelike_scalar_to_string_dtype(self): def test_constructor_sparse_datetime64(self, values): # https://github.com/pandas-dev/pandas/issues/35762 dtype = pd.SparseDtype("datetime64[ns]") - result = pd.Series(values, dtype=dtype) + result = Series(values, dtype=dtype) arr = pd.arrays.SparseArray(values, dtype=dtype) - expected = pd.Series(arr) + expected = Series(arr) tm.assert_series_equal(result, expected) def test_construction_from_ordered_collection(self): diff --git a/pandas/tests/series/test_datetime_values.py b/pandas/tests/series/test_datetime_values.py index b0926089bd7b4..53b465fa814b3 100644 --- a/pandas/tests/series/test_datetime_values.py +++ b/pandas/tests/series/test_datetime_values.py @@ -192,7 +192,7 @@ def compare(s, name): exp = Series(np.array([0, 1, 2], dtype="int64"), index=index, name="xxx") tm.assert_series_equal(s.dt.second, exp) - exp = pd.Series([s[0]] * 3, index=index, name="xxx") + exp = Series([s[0]] * 3, index=index, name="xxx") tm.assert_series_equal(s.dt.normalize(), exp) # periodindex @@ -350,7 +350,7 @@ def test_dt_namespace_accessor_categorical(self): def test_dt_tz_localize_categorical(self, tz_aware_fixture): # GH 27952 tz = tz_aware_fixture - datetimes = pd.Series( + datetimes = Series( ["2019-01-01", "2019-01-01", "2019-01-02"], dtype="datetime64[ns]" ) categorical = datetimes.astype("category") @@ -361,7 +361,7 @@ def test_dt_tz_localize_categorical(self, tz_aware_fixture): def test_dt_tz_convert_categorical(self, tz_aware_fixture): # GH 27952 tz = tz_aware_fixture - datetimes = pd.Series( + datetimes = Series( ["2019-01-01", "2019-01-01", "2019-01-02"], dtype="datetime64[ns, MET]" ) categorical = datetimes.astype("category") @@ -372,7 +372,7 @@ def test_dt_tz_convert_categorical(self, tz_aware_fixture): @pytest.mark.parametrize("accessor", ["year", "month", "day"]) def test_dt_other_accessors_categorical(self, accessor): # GH 27952 - datetimes = pd.Series( + datetimes = Series( ["2018-01-01", "2018-01-01", "2019-01-02"], dtype="datetime64[ns]" ) categorical = datetimes.astype("category") @@ -657,16 +657,16 @@ def test_dt_timetz_accessor(self, tz_naive_fixture): def test_setitem_with_string_index(self): # GH 23451 - x = pd.Series([1, 2, 3], index=["Date", "b", "other"]) + x = Series([1, 2, 3], index=["Date", "b", "other"]) x["Date"] = date.today() assert x.Date == date.today() assert x["Date"] == date.today() def test_setitem_with_different_tz(self): # GH#24024 - ser = pd.Series(pd.date_range("2000", periods=2, tz="US/Central")) + ser = Series(pd.date_range("2000", periods=2, tz="US/Central")) ser[0] = pd.Timestamp("2000", tz="US/Eastern") - expected = pd.Series( + expected = Series( [ pd.Timestamp("2000-01-01 00:00:00-05:00", tz="US/Eastern"), pd.Timestamp("2000-01-02 00:00:00-06:00", tz="US/Central"), @@ -688,7 +688,7 @@ def test_setitem_with_different_tz(self): ], ) def test_isocalendar(self, input_series, expected_output): - result = pd.to_datetime(pd.Series(input_series)).dt.isocalendar() + result = pd.to_datetime(Series(input_series)).dt.isocalendar() expected_frame = pd.DataFrame( expected_output, columns=["year", "week", "day"], dtype="UInt32" ) @@ -697,7 +697,7 @@ def test_isocalendar(self, input_series, expected_output): def test_week_and_weekofyear_are_deprecated(): # GH#33595 Deprecate week and weekofyear - series = pd.to_datetime(pd.Series(["2020-01-01"])) + series = pd.to_datetime(Series(["2020-01-01"])) with tm.assert_produces_warning(FutureWarning): series.dt.week with tm.assert_produces_warning(FutureWarning): @@ -706,7 +706,7 @@ def test_week_and_weekofyear_are_deprecated(): def test_normalize_pre_epoch_dates(): # GH: 36294 - s = pd.to_datetime(pd.Series(["1969-01-01 09:00:00", "2016-01-01 09:00:00"])) + s = pd.to_datetime(Series(["1969-01-01 09:00:00", "2016-01-01 09:00:00"])) result = s.dt.normalize() - expected = pd.to_datetime(pd.Series(["1969-01-01", "2016-01-01"])) + expected = pd.to_datetime(Series(["1969-01-01", "2016-01-01"])) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index ae89e16ca7667..29c1728be786a 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -482,7 +482,7 @@ def test_infer_objects_series(self): ) def test_values_compatibility(self, data): # https://github.com/pandas-dev/pandas/issues/23995 - result = pd.Series(data).values + result = Series(data).values expected = np.array(data.astype(object)) tm.assert_numpy_array_equal(result, expected) diff --git a/pandas/tests/series/test_internals.py b/pandas/tests/series/test_internals.py index 51410fce7efae..488bd120ac405 100644 --- a/pandas/tests/series/test_internals.py +++ b/pandas/tests/series/test_internals.py @@ -204,31 +204,31 @@ def test_convert_preserve_all_bool(self): tm.assert_series_equal(r, e) def test_constructor_no_pandas_array(self): - ser = pd.Series([1, 2, 3]) - result = pd.Series(ser.array) + ser = Series([1, 2, 3]) + result = Series(ser.array) tm.assert_series_equal(ser, result) assert isinstance(result._mgr.blocks[0], IntBlock) def test_astype_no_pandas_dtype(self): # https://github.com/pandas-dev/pandas/pull/24866 - ser = pd.Series([1, 2], dtype="int64") + ser = Series([1, 2], dtype="int64") # Don't have PandasDtype in the public API, so we use `.array.dtype`, # which is a PandasDtype. result = ser.astype(ser.array.dtype) tm.assert_series_equal(result, ser) def test_from_array(self): - result = pd.Series(pd.array(["1H", "2H"], dtype="timedelta64[ns]")) + result = Series(pd.array(["1H", "2H"], dtype="timedelta64[ns]")) assert result._mgr.blocks[0].is_extension is False - result = pd.Series(pd.array(["2015"], dtype="datetime64[ns]")) + result = Series(pd.array(["2015"], dtype="datetime64[ns]")) assert result._mgr.blocks[0].is_extension is False def test_from_list_dtype(self): - result = pd.Series(["1H", "2H"], dtype="timedelta64[ns]") + result = Series(["1H", "2H"], dtype="timedelta64[ns]") assert result._mgr.blocks[0].is_extension is False - result = pd.Series(["2015"], dtype="datetime64[ns]") + result = Series(["2015"], dtype="datetime64[ns]") assert result._mgr.blocks[0].is_extension is False diff --git a/pandas/tests/series/test_logical_ops.py b/pandas/tests/series/test_logical_ops.py index 217e5ae9ee32e..df7ea46dc4f86 100644 --- a/pandas/tests/series/test_logical_ops.py +++ b/pandas/tests/series/test_logical_ops.py @@ -153,37 +153,37 @@ def test_logical_operators_bool_dtype_with_int(self): def test_logical_ops_bool_dtype_with_ndarray(self): # make sure we operate on ndarray the same as Series - left = pd.Series([True, True, True, False, True]) + left = Series([True, True, True, False, True]) right = [True, False, None, True, np.nan] - expected = pd.Series([True, False, False, False, False]) + expected = Series([True, False, False, False, False]) result = left & right tm.assert_series_equal(result, expected) result = left & np.array(right) tm.assert_series_equal(result, expected) result = left & pd.Index(right) tm.assert_series_equal(result, expected) - result = left & pd.Series(right) + result = left & Series(right) tm.assert_series_equal(result, expected) - expected = pd.Series([True, True, True, True, True]) + expected = Series([True, True, True, True, True]) result = left | right tm.assert_series_equal(result, expected) result = left | np.array(right) tm.assert_series_equal(result, expected) result = left | pd.Index(right) tm.assert_series_equal(result, expected) - result = left | pd.Series(right) + result = left | Series(right) tm.assert_series_equal(result, expected) - expected = pd.Series([False, True, True, True, True]) + expected = Series([False, True, True, True, True]) result = left ^ right tm.assert_series_equal(result, expected) result = left ^ np.array(right) tm.assert_series_equal(result, expected) result = left ^ pd.Index(right) tm.assert_series_equal(result, expected) - result = left ^ pd.Series(right) + result = left ^ Series(right) tm.assert_series_equal(result, expected) def test_logical_operators_int_dtype_with_bool_dtype_and_reindex(self): @@ -304,11 +304,11 @@ def test_reversed_logical_op_with_index_returns_series(self, op): idx1 = Index([True, False, True, False]) idx2 = Index([1, 0, 1, 0]) - expected = pd.Series(op(idx1.values, ser.values)) + expected = Series(op(idx1.values, ser.values)) result = op(ser, idx1) tm.assert_series_equal(result, expected) - expected = pd.Series(op(idx2.values, ser.values)) + expected = Series(op(idx2.values, ser.values)) result = op(ser, idx2) tm.assert_series_equal(result, expected) @@ -431,18 +431,18 @@ def test_logical_ops_label_based(self): def test_logical_ops_df_compat(self): # GH#1134 - s1 = pd.Series([True, False, True], index=list("ABC"), name="x") - s2 = pd.Series([True, True, False], index=list("ABD"), name="x") + s1 = Series([True, False, True], index=list("ABC"), name="x") + s2 = Series([True, True, False], index=list("ABD"), name="x") - exp = pd.Series([True, False, False, False], index=list("ABCD"), name="x") + exp = Series([True, False, False, False], index=list("ABCD"), name="x") tm.assert_series_equal(s1 & s2, exp) tm.assert_series_equal(s2 & s1, exp) # True | np.nan => True - exp_or1 = pd.Series([True, True, True, False], index=list("ABCD"), name="x") + exp_or1 = Series([True, True, True, False], index=list("ABCD"), name="x") tm.assert_series_equal(s1 | s2, exp_or1) # np.nan | True => np.nan, filled with False - exp_or = pd.Series([True, True, False, False], index=list("ABCD"), name="x") + exp_or = Series([True, True, False, False], index=list("ABCD"), name="x") tm.assert_series_equal(s2 | s1, exp_or) # DataFrame doesn't fill nan with False @@ -454,18 +454,18 @@ def test_logical_ops_df_compat(self): tm.assert_frame_equal(s2.to_frame() | s1.to_frame(), exp_or.to_frame()) # different length - s3 = pd.Series([True, False, True], index=list("ABC"), name="x") - s4 = pd.Series([True, True, True, True], index=list("ABCD"), name="x") + s3 = Series([True, False, True], index=list("ABC"), name="x") + s4 = Series([True, True, True, True], index=list("ABCD"), name="x") - exp = pd.Series([True, False, True, False], index=list("ABCD"), name="x") + exp = Series([True, False, True, False], index=list("ABCD"), name="x") tm.assert_series_equal(s3 & s4, exp) tm.assert_series_equal(s4 & s3, exp) # np.nan | True => np.nan, filled with False - exp_or1 = pd.Series([True, True, True, False], index=list("ABCD"), name="x") + exp_or1 = Series([True, True, True, False], index=list("ABCD"), name="x") tm.assert_series_equal(s3 | s4, exp_or1) # True | np.nan => True - exp_or = pd.Series([True, True, True, True], index=list("ABCD"), name="x") + exp_or = Series([True, True, True, True], index=list("ABCD"), name="x") tm.assert_series_equal(s4 | s3, exp_or) tm.assert_frame_equal(s3.to_frame() & s4.to_frame(), exp.to_frame()) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 0144e4257efe0..712921f70e46f 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -172,7 +172,7 @@ def test_datetime64_tz_fillna(self, tz): pd.NaT, ] ) - null_loc = pd.Series([False, True, False, True]) + null_loc = Series([False, True, False, True]) result = s.fillna(pd.Timestamp("2011-01-02 10:00")) expected = Series( @@ -247,7 +247,7 @@ def test_datetime64_tz_fillna(self, tz): idx = pd.DatetimeIndex( ["2011-01-01 10:00", pd.NaT, "2011-01-03 10:00", pd.NaT], tz=tz ) - s = pd.Series(idx) + s = Series(idx) assert s.dtype == f"datetime64[ns, {tz}]" tm.assert_series_equal(pd.isna(s), null_loc) @@ -366,8 +366,8 @@ def test_datetime64_tz_fillna(self, tz): def test_fillna_dt64tz_with_method(self): # with timezone # GH 15855 - ser = pd.Series([pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.NaT]) - exp = pd.Series( + ser = Series([pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.NaT]) + exp = Series( [ pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.Timestamp("2012-11-11 00:00:00+01:00"), @@ -375,8 +375,8 @@ def test_fillna_dt64tz_with_method(self): ) tm.assert_series_equal(ser.fillna(method="pad"), exp) - ser = pd.Series([pd.NaT, pd.Timestamp("2012-11-11 00:00:00+01:00")]) - exp = pd.Series( + ser = Series([pd.NaT, pd.Timestamp("2012-11-11 00:00:00+01:00")]) + exp = Series( [ pd.Timestamp("2012-11-11 00:00:00+01:00"), pd.Timestamp("2012-11-11 00:00:00+01:00"), @@ -421,13 +421,13 @@ def test_fillna_consistency(self): def test_datetime64tz_fillna_round_issue(self): # GH 14872 - data = pd.Series( + data = Series( [pd.NaT, pd.NaT, datetime(2016, 12, 12, 22, 24, 6, 100001, tzinfo=pytz.utc)] ) filled = data.fillna(method="bfill") - expected = pd.Series( + expected = Series( [ datetime(2016, 12, 12, 22, 24, 6, 100001, tzinfo=pytz.utc), datetime(2016, 12, 12, 22, 24, 6, 100001, tzinfo=pytz.utc), @@ -440,15 +440,15 @@ def test_datetime64tz_fillna_round_issue(self): def test_fillna_downcast(self): # GH 15277 # infer int64 from float64 - s = pd.Series([1.0, np.nan]) + s = Series([1.0, np.nan]) result = s.fillna(0, downcast="infer") - expected = pd.Series([1, 0]) + expected = Series([1, 0]) tm.assert_series_equal(result, expected) # infer int64 from float64 when fillna value is a dict - s = pd.Series([1.0, np.nan]) + s = Series([1.0, np.nan]) result = s.fillna({1: 0}, downcast="infer") - expected = pd.Series([1, 0]) + expected = Series([1, 0]) tm.assert_series_equal(result, expected) def test_fillna_int(self): @@ -627,7 +627,7 @@ def test_ffill(self): def test_ffill_mixed_dtypes_without_missing_data(self): # GH14956 - series = pd.Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1]) + series = Series([datetime(2015, 1, 1, tzinfo=pytz.utc), 1]) result = series.ffill() tm.assert_series_equal(series, result) @@ -710,7 +710,7 @@ def test_datetime64_tz_dropna(self): idx = pd.DatetimeIndex( ["2011-01-01 10:00", pd.NaT, "2011-01-03 10:00", pd.NaT], tz="Asia/Tokyo" ) - s = pd.Series(idx) + s = Series(idx) assert s.dtype == "datetime64[ns, Asia/Tokyo]" result = s.dropna() expected = Series( diff --git a/pandas/tests/series/test_period.py b/pandas/tests/series/test_period.py index b54c09e5750fd..52a398a00dfe5 100644 --- a/pandas/tests/series/test_period.py +++ b/pandas/tests/series/test_period.py @@ -15,7 +15,7 @@ def test_auto_conversion(self): series = Series(list(period_range("2000-01-01", periods=10, freq="D"))) assert series.dtype == "Period[D]" - series = pd.Series( + series = Series( [pd.Period("2011-01-01", freq="D"), pd.Period("2011-02-01", freq="D")] ) assert series.dtype == "Period[D]" diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index bab3853e3bd1d..c4cd12fcbdf3b 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -99,9 +99,9 @@ def test_asfreq_resample_set_correct_freq(self): def test_view_tz(self): # GH#24024 - ser = pd.Series(pd.date_range("2000", periods=4, tz="US/Central")) + ser = Series(pd.date_range("2000", periods=4, tz="US/Central")) result = ser.view("i8") - expected = pd.Series( + expected = Series( [ 946706400000000000, 946792800000000000, @@ -113,7 +113,7 @@ def test_view_tz(self): @pytest.mark.parametrize("tz", [None, "US/Central"]) def test_asarray_object_dt64(self, tz): - ser = pd.Series(pd.date_range("2000", periods=2, tz=tz)) + ser = Series(pd.date_range("2000", periods=2, tz=tz)) with tm.assert_produces_warning(None): # Future behavior (for tzaware case) with no warning @@ -126,7 +126,7 @@ def test_asarray_object_dt64(self, tz): def test_asarray_tz_naive(self): # This shouldn't produce a warning. - ser = pd.Series(pd.date_range("2000", periods=2)) + ser = Series(pd.date_range("2000", periods=2)) expected = np.array(["2000-01-01", "2000-01-02"], dtype="M8[ns]") result = np.asarray(ser) @@ -134,7 +134,7 @@ def test_asarray_tz_naive(self): def test_asarray_tz_aware(self): tz = "US/Central" - ser = pd.Series(pd.date_range("2000", periods=2, tz=tz)) + ser = Series(pd.date_range("2000", periods=2, tz=tz)) expected = np.array(["2000-01-01T06", "2000-01-02T06"], dtype="M8[ns]") result = np.asarray(ser, dtype="datetime64[ns]") diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index c7fc37a278e83..bcd6a7a7308a3 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -30,7 +30,7 @@ def arrays_for_binary_ufunc(): @pytest.mark.parametrize("ufunc", UNARY_UFUNCS) @pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) def test_unary_ufunc(ufunc, sparse): - # Test that ufunc(Series) == Series(ufunc) + # Test that ufunc(pd.Series) == pd.Series(ufunc) array = np.random.randint(0, 10, 10, dtype="int64") array[::2] = 0 if sparse: @@ -49,13 +49,13 @@ def test_unary_ufunc(ufunc, sparse): @pytest.mark.parametrize("sparse", SPARSE, ids=SPARSE_IDS) @pytest.mark.parametrize("flip", [True, False], ids=["flipped", "straight"]) def test_binary_ufunc_with_array(flip, sparse, ufunc, arrays_for_binary_ufunc): - # Test that ufunc(Series(a), array) == Series(ufunc(a, b)) + # Test that ufunc(pd.Series(a), array) == pd.Series(ufunc(a, b)) a1, a2 = arrays_for_binary_ufunc if sparse: a1 = SparseArray(a1, dtype=pd.SparseDtype("int64", 0)) a2 = SparseArray(a2, dtype=pd.SparseDtype("int64", 0)) - name = "name" # op(Series, array) preserves the name. + name = "name" # op(pd.Series, array) preserves the name. series = pd.Series(a1, name=name) other = a2 @@ -76,14 +76,14 @@ def test_binary_ufunc_with_array(flip, sparse, ufunc, arrays_for_binary_ufunc): @pytest.mark.parametrize("flip", [True, False], ids=["flipped", "straight"]) def test_binary_ufunc_with_index(flip, sparse, ufunc, arrays_for_binary_ufunc): # Test that - # * func(Series(a), Series(b)) == Series(ufunc(a, b)) - # * ufunc(Index, Series) dispatches to Series (returns a Series) + # * func(pd.Series(a), pd.Series(b)) == pd.Series(ufunc(a, b)) + # * ufunc(Index, pd.Series) dispatches to pd.Series (returns a pd.Series) a1, a2 = arrays_for_binary_ufunc if sparse: a1 = SparseArray(a1, dtype=pd.SparseDtype("int64", 0)) a2 = SparseArray(a2, dtype=pd.SparseDtype("int64", 0)) - name = "name" # op(Series, array) preserves the name. + name = "name" # op(pd.Series, array) preserves the name. series = pd.Series(a1, name=name) other = pd.Index(a2, name=name).astype("int64") @@ -107,14 +107,14 @@ def test_binary_ufunc_with_series( flip, shuffle, sparse, ufunc, arrays_for_binary_ufunc ): # Test that - # * func(Series(a), Series(b)) == Series(ufunc(a, b)) + # * func(pd.Series(a), pd.Series(b)) == pd.Series(ufunc(a, b)) # with alignment between the indices a1, a2 = arrays_for_binary_ufunc if sparse: a1 = SparseArray(a1, dtype=pd.SparseDtype("int64", 0)) a2 = SparseArray(a2, dtype=pd.SparseDtype("int64", 0)) - name = "name" # op(Series, array) preserves the name. + name = "name" # op(pd.Series, array) preserves the name. series = pd.Series(a1, name=name) other = pd.Series(a2, name=name) @@ -146,8 +146,8 @@ def test_binary_ufunc_with_series( @pytest.mark.parametrize("flip", [True, False]) def test_binary_ufunc_scalar(ufunc, sparse, flip, arrays_for_binary_ufunc): # Test that - # * ufunc(Series, scalar) == Series(ufunc(array, scalar)) - # * ufunc(Series, scalar) == ufunc(scalar, Series) + # * ufunc(pd.Series, scalar) == pd.Series(ufunc(array, scalar)) + # * ufunc(pd.Series, scalar) == ufunc(scalar, pd.Series) array, _ = arrays_for_binary_ufunc if sparse: array = SparseArray(array) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 37d92e220e4cd..3a1279c481a1d 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -851,10 +851,10 @@ def test_same_nan_is_in_large(self): def test_same_nan_is_in_large_series(self): # https://github.com/pandas-dev/pandas/issues/22205 s = np.tile(1.0, 1_000_001) - series = pd.Series(s) + series = Series(s) s[0] = np.nan result = series.isin([np.nan, 1]) - expected = pd.Series(np.ones(len(s), dtype=bool)) + expected = Series(np.ones(len(s), dtype=bool)) tm.assert_series_equal(result, expected) def test_same_object_is_in(self): diff --git a/pandas/tests/test_nanops.py b/pandas/tests/test_nanops.py index c45e4508c6153..398457f81a266 100644 --- a/pandas/tests/test_nanops.py +++ b/pandas/tests/test_nanops.py @@ -1036,7 +1036,7 @@ def test_use_bottleneck(): ) def test_numpy_ops(numpy_op, expected): # GH8383 - result = numpy_op(pd.Series([1, 2, 3, 4])) + result = numpy_op(Series([1, 2, 3, 4])) assert result == expected @@ -1062,7 +1062,7 @@ def test_numpy_ops(numpy_op, expected): ) def test_nanops_independent_of_mask_param(operation): # GH22764 - s = pd.Series([1, 2, np.nan, 3, np.nan, 4]) + s = Series([1, 2, np.nan, 3, np.nan, 4]) mask = s.isna() median_expected = operation(s) median_result = operation(s, mask=mask) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 61df5d4d5fdd6..9be5abb9dda65 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -132,7 +132,7 @@ def any_string_method(request): Examples -------- >>> def test_something(any_string_method): - ... s = pd.Series(['a', 'b', np.nan, 'd']) + ... s = Series(['a', 'b', np.nan, 'd']) ... ... method_name, args, kwargs = any_string_method ... method = getattr(s.str, method_name) @@ -183,7 +183,7 @@ def any_allowed_skipna_inferred_dtype(request): ... assert lib.infer_dtype(values, skipna=True) == inferred_dtype ... ... # constructor for .str-accessor will also pass - ... pd.Series(values).str + ... Series(values).str """ inferred_dtype, values = request.param values = np.array(values, dtype=object) # object dtype to avoid casting @@ -2546,8 +2546,8 @@ def test_split(self): @pytest.mark.parametrize("dtype", [object, "string"]) @pytest.mark.parametrize("method", ["split", "rsplit"]) def test_split_n(self, dtype, method): - s = pd.Series(["a b", pd.NA, "b c"], dtype=dtype) - expected = pd.Series([["a", "b"], pd.NA, ["b", "c"]]) + s = Series(["a b", pd.NA, "b c"], dtype=dtype) + expected = Series([["a", "b"], pd.NA, ["b", "c"]]) result = getattr(s.str, method)(" ", n=None) tm.assert_series_equal(result, expected) @@ -3653,14 +3653,14 @@ def test_string_array_extract(): @pytest.mark.parametrize("klass", [tuple, list, np.array, pd.Series, pd.Index]) def test_cat_different_classes(klass): # https://github.com/pandas-dev/pandas/issues/33425 - s = pd.Series(["a", "b", "c"]) + s = Series(["a", "b", "c"]) result = s.str.cat(klass(["x", "y", "z"])) - expected = pd.Series(["ax", "by", "cz"]) + expected = Series(["ax", "by", "cz"]) tm.assert_series_equal(result, expected) def test_str_get_stringarray_multiple_nans(): - s = pd.Series(pd.array(["a", "ab", pd.NA, "abc"])) + s = Series(pd.array(["a", "ab", pd.NA, "abc"])) result = s.str.get(2) - expected = pd.Series(pd.array([pd.NA, pd.NA, pd.NA, "c"])) + expected = Series(pd.array([pd.NA, pd.NA, pd.NA, "c"])) tm.assert_series_equal(result, expected) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 63f9a2532fa73..a070d45089f96 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -714,17 +714,17 @@ def test_to_datetime_utc_true( def test_to_datetime_utc_true_with_series_single_value(self, cache): # GH 15760 UTC=True with Series ts = 1.5e18 - result = pd.to_datetime(pd.Series([ts]), utc=True, cache=cache) - expected = pd.Series([pd.Timestamp(ts, tz="utc")]) + result = pd.to_datetime(Series([ts]), utc=True, cache=cache) + expected = Series([pd.Timestamp(ts, tz="utc")]) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_utc_true_with_series_tzaware_string(self, cache): ts = "2013-01-01 00:00:00-01:00" expected_ts = "2013-01-01 01:00:00" - data = pd.Series([ts] * 3) + data = Series([ts] * 3) result = pd.to_datetime(data, utc=True, cache=cache) - expected = pd.Series([pd.Timestamp(expected_ts, tz="utc")] * 3) + expected = Series([pd.Timestamp(expected_ts, tz="utc")] * 3) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("cache", [True, False]) @@ -736,8 +736,8 @@ def test_to_datetime_utc_true_with_series_tzaware_string(self, cache): ], ) def test_to_datetime_utc_true_with_series_datetime_ns(self, cache, date, dtype): - expected = pd.Series([pd.Timestamp("2013-01-01 01:00:00", tz="UTC")]) - result = pd.to_datetime(pd.Series([date], dtype=dtype), utc=True, cache=cache) + expected = Series([pd.Timestamp("2013-01-01 01:00:00", tz="UTC")]) + result = pd.to_datetime(Series([date], dtype=dtype), utc=True, cache=cache) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("cache", [True, False]) @@ -929,7 +929,7 @@ def test_to_datetime_from_deque(self): def test_to_datetime_cache_series(self, utc, format): date = "20130101 00:00:00" test_dates = [date] * 10 ** 5 - data = pd.Series(test_dates) + data = Series(test_dates) result = pd.to_datetime(data, utc=utc, format=format, cache=True) expected = pd.to_datetime(data, utc=utc, format=format, cache=False) tm.assert_series_equal(result, expected) @@ -1049,7 +1049,7 @@ def test_iso8601_strings_mixed_offsets_with_naive(self): def test_mixed_offsets_with_native_datetime_raises(self): # GH 25978 - s = pd.Series( + s = Series( [ "nan", pd.Timestamp("1990-01-01"), @@ -1420,7 +1420,7 @@ def test_dataframe_utc_true(self): # GH 23760 df = pd.DataFrame({"year": [2015, 2016], "month": [2, 3], "day": [4, 5]}) result = pd.to_datetime(df, utc=True) - expected = pd.Series( + expected = Series( np.array(["2015-02-04", "2016-03-05"], dtype="datetime64[ns]") ).dt.tz_localize("UTC") tm.assert_series_equal(result, expected) @@ -1579,7 +1579,7 @@ def test_to_datetime_with_apply(self, cache): result = td.apply(pd.to_datetime, format="%b %y", cache=cache) tm.assert_series_equal(result, expected) - td = pd.Series(["May 04", "Jun 02", ""], index=[1, 2, 3]) + td = Series(["May 04", "Jun 02", ""], index=[1, 2, 3]) msg = r"time data '' does not match format '%b %y' \(match\)" with pytest.raises(ValueError, match=msg): pd.to_datetime(td, format="%b %y", errors="raise", cache=cache) @@ -1818,7 +1818,7 @@ def test_guess_datetime_format_for_array(self): class TestToDatetimeInferFormat: @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_infer_datetime_format_consistent_format(self, cache): - s = pd.Series(pd.date_range("20000101", periods=50, freq="H")) + s = Series(pd.date_range("20000101", periods=50, freq="H")) test_formats = ["%m-%d-%Y", "%m/%d/%Y %H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S.%f"] @@ -1842,7 +1842,7 @@ def test_to_datetime_infer_datetime_format_consistent_format(self, cache): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_infer_datetime_format_inconsistent_format(self, cache): - s = pd.Series( + s = Series( np.array( ["01/01/2011 00:00:00", "01-02-2011 00:00:00", "2011-01-03T00:00:00"] ) @@ -1855,7 +1855,7 @@ def test_to_datetime_infer_datetime_format_inconsistent_format(self, cache): pd.to_datetime(s, infer_datetime_format=True, cache=cache), ) - s = pd.Series(np.array(["Jan/01/2011", "Feb/01/2011", "Mar/01/2011"])) + s = Series(np.array(["Jan/01/2011", "Feb/01/2011", "Mar/01/2011"])) tm.assert_series_equal( pd.to_datetime(s, infer_datetime_format=False, cache=cache), @@ -1864,7 +1864,7 @@ def test_to_datetime_infer_datetime_format_inconsistent_format(self, cache): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_infer_datetime_format_series_with_nans(self, cache): - s = pd.Series( + s = Series( np.array(["01/01/2011 00:00:00", np.nan, "01/03/2011 00:00:00", np.nan]) ) tm.assert_series_equal( @@ -1874,7 +1874,7 @@ def test_to_datetime_infer_datetime_format_series_with_nans(self, cache): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_infer_datetime_format_series_start_with_nans(self, cache): - s = pd.Series( + s = Series( np.array( [ np.nan, @@ -1896,9 +1896,9 @@ def test_to_datetime_infer_datetime_format_series_start_with_nans(self, cache): ) def test_infer_datetime_format_tz_name(self, tz_name, offset): # GH 33133 - s = pd.Series([f"2019-02-02 08:07:13 {tz_name}"]) + s = Series([f"2019-02-02 08:07:13 {tz_name}"]) result = to_datetime(s, infer_datetime_format=True) - expected = pd.Series( + expected = Series( [pd.Timestamp("2019-02-02 08:07:13").tz_localize(pytz.FixedOffset(offset))] ) tm.assert_series_equal(result, expected) @@ -1906,8 +1906,8 @@ def test_infer_datetime_format_tz_name(self, tz_name, offset): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_iso8601_noleading_0s(self, cache): # GH 11871 - s = pd.Series(["2014-1-1", "2014-2-2", "2015-3-3"]) - expected = pd.Series( + s = Series(["2014-1-1", "2014-2-2", "2015-3-3"]) + expected = Series( [ pd.Timestamp("2014-01-01"), pd.Timestamp("2014-02-02"), @@ -2410,13 +2410,13 @@ def test_should_cache_errors(unique_share, check_count, err_message): def test_nullable_integer_to_datetime(): # Test for #30050 - ser = pd.Series([1, 2, None, 2 ** 61, None]) + ser = Series([1, 2, None, 2 ** 61, None]) ser = ser.astype("Int64") ser_copy = ser.copy() res = pd.to_datetime(ser, unit="ns") - expected = pd.Series( + expected = Series( [ np.datetime64("1970-01-01 00:00:00.000000001"), np.datetime64("1970-01-01 00:00:00.000000002"), diff --git a/pandas/tests/tools/test_to_numeric.py b/pandas/tests/tools/test_to_numeric.py index b22f249de2826..713607d087bc0 100644 --- a/pandas/tests/tools/test_to_numeric.py +++ b/pandas/tests/tools/test_to_numeric.py @@ -571,8 +571,8 @@ def test_downcast_limits(dtype, downcast, min_max): "ser,expected", [ ( - pd.Series([0, 9223372036854775808]), - pd.Series([0, 9223372036854775808], dtype=np.uint64), + Series([0, 9223372036854775808]), + Series([0, 9223372036854775808], dtype=np.uint64), ) ], ) @@ -647,7 +647,7 @@ def test_failure_to_convert_uint64_string_to_NaN(): assert np.isnan(result) ser = Series([32, 64, np.nan]) - result = to_numeric(pd.Series(["32", "64", "uint64"]), errors="coerce") + result = to_numeric(Series(["32", "64", "uint64"]), errors="coerce") tm.assert_series_equal(result, ser) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index 53746aa048663..0f56fb0b93642 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -301,14 +301,14 @@ def test_series_equal_exact_for_nonnumeric(): @pytest.mark.parametrize("right_dtype", ["Int32", "int64"]) def test_assert_series_equal_ignore_extension_dtype_mismatch(right_dtype): # https://github.com/pandas-dev/pandas/issues/35715 - left = pd.Series([1, 2, 3], dtype="Int64") - right = pd.Series([1, 2, 3], dtype=right_dtype) + left = Series([1, 2, 3], dtype="Int64") + right = Series([1, 2, 3], dtype=right_dtype) tm.assert_series_equal(left, right, check_dtype=False) def test_allows_duplicate_labels(): - left = pd.Series([1]) - right = pd.Series([1]).set_flags(allows_duplicate_labels=False) + left = Series([1]) + right = Series([1]).set_flags(allows_duplicate_labels=False) tm.assert_series_equal(left, left) tm.assert_series_equal(right, right) tm.assert_series_equal(left, right, check_flags=False) diff --git a/pandas/tests/util/test_hashing.py b/pandas/tests/util/test_hashing.py index ff29df39e1871..f761b6b4ffd7a 100644 --- a/pandas/tests/util/test_hashing.py +++ b/pandas/tests/util/test_hashing.py @@ -302,12 +302,12 @@ def test_hash_with_tuple(): df = pd.DataFrame({"data": [tuple("1"), tuple("2")]}) result = hash_pandas_object(df) - expected = pd.Series([10345501319357378243, 8331063931016360761], dtype=np.uint64) + expected = Series([10345501319357378243, 8331063931016360761], dtype=np.uint64) tm.assert_series_equal(result, expected) df2 = pd.DataFrame({"data": [tuple([1]), tuple([2])]}) result = hash_pandas_object(df2) - expected = pd.Series([9408946347443669104, 3278256261030523334], dtype=np.uint64) + expected = Series([9408946347443669104, 3278256261030523334], dtype=np.uint64) tm.assert_series_equal(result, expected) # require that the elements of such tuples are themselves hashable @@ -319,6 +319,6 @@ def test_hash_with_tuple(): def test_hash_object_none_key(): # https://github.com/pandas-dev/pandas/issues/30887 - result = pd.util.hash_pandas_object(pd.Series(["a", "b"]), hash_key=None) - expected = pd.Series([4578374827886788867, 17338122309987883691], dtype="uint64") + result = pd.util.hash_pandas_object(Series(["a", "b"]), hash_key=None) + expected = Series([4578374827886788867, 17338122309987883691], dtype="uint64") tm.assert_series_equal(result, expected) diff --git a/pandas/tests/window/moments/test_moments_consistency_rolling.py b/pandas/tests/window/moments/test_moments_consistency_rolling.py index 96ad83f6b40b1..6ab53c8e2ec0d 100644 --- a/pandas/tests/window/moments/test_moments_consistency_rolling.py +++ b/pandas/tests/window/moments/test_moments_consistency_rolling.py @@ -143,8 +143,8 @@ def test_rolling_apply_consistency( @pytest.mark.parametrize("window", range(7)) def test_rolling_corr_with_zero_variance(window): # GH 18430 - s = pd.Series(np.zeros(20)) - other = pd.Series(np.arange(20)) + s = Series(np.zeros(20)) + other = Series(np.arange(20)) assert s.rolling(window=window).corr(other=other).isna().all() diff --git a/pandas/tests/window/moments/test_moments_ewm.py b/pandas/tests/window/moments/test_moments_ewm.py index 287cd7ebba536..605b85344ba76 100644 --- a/pandas/tests/window/moments/test_moments_ewm.py +++ b/pandas/tests/window/moments/test_moments_ewm.py @@ -2,7 +2,6 @@ from numpy.random import randn import pytest -import pandas as pd from pandas import DataFrame, Series import pandas._testing as tm @@ -20,7 +19,7 @@ def test_ewma_frame(frame, name): def test_ewma_adjust(): - vals = pd.Series(np.zeros(1000)) + vals = Series(np.zeros(1000)) vals[5] = 1 result = vals.ewm(span=100, adjust=False).mean().sum() assert np.abs(result - 1) < 1e-2 @@ -295,7 +294,7 @@ def test_ewm_domain_checks(arr): @pytest.mark.parametrize("method", ["mean", "vol", "var"]) def test_ew_empty_series(method): - vals = pd.Series([], dtype=np.float64) + vals = Series([], dtype=np.float64) ewm = vals.ewm(3) result = getattr(ewm, method)() diff --git a/pandas/tests/window/moments/test_moments_rolling.py b/pandas/tests/window/moments/test_moments_rolling.py index 488306d0585c5..2f622c2bc3e60 100644 --- a/pandas/tests/window/moments/test_moments_rolling.py +++ b/pandas/tests/window/moments/test_moments_rolling.py @@ -74,17 +74,17 @@ def test_cmov_window(): def test_cmov_window_corner(): # GH 8238 # all nan - vals = pd.Series([np.nan] * 10) + vals = Series([np.nan] * 10) result = vals.rolling(5, center=True, win_type="boxcar").mean() assert np.isnan(result).all() # empty - vals = pd.Series([], dtype=object) + vals = Series([], dtype=object) result = vals.rolling(5, center=True, win_type="boxcar").mean() assert len(result) == 0 # shorter than window - vals = pd.Series(np.random.randn(5)) + vals = Series(np.random.randn(5)) result = vals.rolling(10, win_type="boxcar").mean() assert np.isnan(result).all() assert len(result) == 5 @@ -523,22 +523,22 @@ def test_cmov_window_special_linear_range(win_types_special): def test_rolling_min_min_periods(): - a = pd.Series([1, 2, 3, 4, 5]) + a = Series([1, 2, 3, 4, 5]) result = a.rolling(window=100, min_periods=1).min() - expected = pd.Series(np.ones(len(a))) + expected = Series(np.ones(len(a))) tm.assert_series_equal(result, expected) msg = "min_periods 5 must be <= window 3" with pytest.raises(ValueError, match=msg): - pd.Series([1, 2, 3]).rolling(window=3, min_periods=5).min() + Series([1, 2, 3]).rolling(window=3, min_periods=5).min() def test_rolling_max_min_periods(): - a = pd.Series([1, 2, 3, 4, 5], dtype=np.float64) + a = Series([1, 2, 3, 4, 5], dtype=np.float64) b = a.rolling(window=100, min_periods=1).max() tm.assert_almost_equal(a, b) msg = "min_periods 5 must be <= window 3" with pytest.raises(ValueError, match=msg): - pd.Series([1, 2, 3]).rolling(window=3, min_periods=5).max() + Series([1, 2, 3]).rolling(window=3, min_periods=5).max() def test_rolling_quantile_np_percentile(): @@ -610,17 +610,17 @@ def test_rolling_quantile_param(): def test_rolling_std_1obs(): - vals = pd.Series([1.0, 2.0, 3.0, 4.0, 5.0]) + vals = Series([1.0, 2.0, 3.0, 4.0, 5.0]) result = vals.rolling(1, min_periods=1).std() - expected = pd.Series([np.nan] * 5) + expected = Series([np.nan] * 5) tm.assert_series_equal(result, expected) result = vals.rolling(1, min_periods=1).std(ddof=0) - expected = pd.Series([0.0] * 5) + expected = Series([0.0] * 5) tm.assert_series_equal(result, expected) - result = pd.Series([np.nan, np.nan, 3, 4, 5]).rolling(3, min_periods=2).std() + result = Series([np.nan, np.nan, 3, 4, 5]).rolling(3, min_periods=2).std() assert np.isnan(result[2]) @@ -629,7 +629,7 @@ def test_rolling_std_neg_sqrt(): # Test move_nanstd for neg sqrt. - a = pd.Series( + a = Series( [ 0.0011448196318903589, 0.00028718669878572767, diff --git a/pandas/tests/window/test_grouper.py b/pandas/tests/window/test_grouper.py index 5b25577602216..fbdf8c775530a 100644 --- a/pandas/tests/window/test_grouper.py +++ b/pandas/tests/window/test_grouper.py @@ -550,7 +550,7 @@ def test_groupby_rolling_count_closed_on(self): .rolling("3d", on="date", closed="left")["column1"] .count() ) - expected = pd.Series( + expected = Series( [np.nan, 1.0, 1.0, np.nan, 1.0, 1.0], name="column1", index=pd.MultiIndex.from_tuples( diff --git a/pandas/tests/window/test_rolling.py b/pandas/tests/window/test_rolling.py index f1d54d91c6d22..312b30e4491a6 100644 --- a/pandas/tests/window/test_rolling.py +++ b/pandas/tests/window/test_rolling.py @@ -136,22 +136,20 @@ def test_closed(): def test_closed_empty(closed, arithmetic_win_operators): # GH 26005 func_name = arithmetic_win_operators - ser = pd.Series( - data=np.arange(5), index=pd.date_range("2000", periods=5, freq="2D") - ) + ser = Series(data=np.arange(5), index=pd.date_range("2000", periods=5, freq="2D")) roll = ser.rolling("1D", closed=closed) result = getattr(roll, func_name)() - expected = pd.Series([np.nan] * 5, index=ser.index) + expected = Series([np.nan] * 5, index=ser.index) tm.assert_series_equal(result, expected) @pytest.mark.parametrize("func", ["min", "max"]) def test_closed_one_entry(func): # GH24718 - ser = pd.Series(data=[2], index=pd.date_range("2000", periods=1)) + ser = Series(data=[2], index=pd.date_range("2000", periods=1)) result = getattr(ser.rolling("10D", closed="left"), func)() - tm.assert_series_equal(result, pd.Series([np.nan], index=ser.index)) + tm.assert_series_equal(result, Series([np.nan], index=ser.index)) @pytest.mark.parametrize("func", ["min", "max"]) @@ -166,7 +164,7 @@ def test_closed_one_entry_groupby(func): exp_idx = pd.MultiIndex.from_arrays( arrays=[[1, 1, 2], ser.index], names=("A", None) ) - expected = pd.Series(data=[np.nan, 3, np.nan], index=exp_idx, name="B") + expected = Series(data=[np.nan, 3, np.nan], index=exp_idx, name="B") tm.assert_series_equal(result, expected) @@ -186,23 +184,23 @@ def test_closed_one_entry_groupby(func): ) def test_closed_min_max_datetime(input_dtype, func, closed, expected): # see gh-21704 - ser = pd.Series( + ser = Series( data=np.arange(10).astype(input_dtype), index=pd.date_range("2000", periods=10) ) result = getattr(ser.rolling("3D", closed=closed), func)() - expected = pd.Series(expected, index=ser.index) + expected = Series(expected, index=ser.index) tm.assert_series_equal(result, expected) def test_closed_uneven(): # see gh-21704 - ser = pd.Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) + ser = Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) # uneven ser = ser.drop(index=ser.index[[1, 5]]) result = ser.rolling("3D", closed="left").min() - expected = pd.Series([np.nan, 0, 0, 2, 3, 4, 6, 6], index=ser.index) + expected = Series([np.nan, 0, 0, 2, 3, 4, 6, 6], index=ser.index) tm.assert_series_equal(result, expected) @@ -221,10 +219,10 @@ def test_closed_uneven(): ) def test_closed_min_max_minp(func, closed, expected): # see gh-21704 - ser = pd.Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) + ser = Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) ser[ser.index[-3:]] = np.nan result = getattr(ser.rolling("3D", min_periods=2, closed=closed), func)() - expected = pd.Series(expected, index=ser.index) + expected = Series(expected, index=ser.index) tm.assert_series_equal(result, expected) @@ -239,9 +237,9 @@ def test_closed_min_max_minp(func, closed, expected): ) def test_closed_median_quantile(closed, expected): # GH 26005 - ser = pd.Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) + ser = Series(data=np.arange(10), index=pd.date_range("2000", periods=10)) roll = ser.rolling("3D", closed=closed) - expected = pd.Series(expected, index=ser.index) + expected = Series(expected, index=ser.index) result = roll.median() tm.assert_series_equal(result, expected) @@ -267,8 +265,8 @@ def tests_empty_df_rolling(roller): def test_empty_window_median_quantile(): # GH 26005 - expected = pd.Series([np.nan, np.nan, np.nan]) - roll = pd.Series(np.arange(3)).rolling(0) + expected = Series([np.nan, np.nan, np.nan]) + roll = Series(np.arange(3)).rolling(0) result = roll.median() tm.assert_series_equal(result, expected) @@ -280,27 +278,27 @@ def test_empty_window_median_quantile(): def test_missing_minp_zero(): # https://github.com/pandas-dev/pandas/pull/18921 # minp=0 - x = pd.Series([np.nan]) + x = Series([np.nan]) result = x.rolling(1, min_periods=0).sum() - expected = pd.Series([0.0]) + expected = Series([0.0]) tm.assert_series_equal(result, expected) # minp=1 result = x.rolling(1, min_periods=1).sum() - expected = pd.Series([np.nan]) + expected = Series([np.nan]) tm.assert_series_equal(result, expected) def test_missing_minp_zero_variable(): # https://github.com/pandas-dev/pandas/pull/18921 - x = pd.Series( + x = Series( [np.nan] * 4, index=pd.DatetimeIndex( ["2017-01-01", "2017-01-04", "2017-01-06", "2017-01-07"] ), ) result = x.rolling(pd.Timedelta("2d"), min_periods=0).sum() - expected = pd.Series(0.0, index=x.index) + expected = Series(0.0, index=x.index) tm.assert_series_equal(result, expected) @@ -349,8 +347,8 @@ def test_readonly_array(): # GH-27766 arr = np.array([1, 3, np.nan, 3, 5]) arr.setflags(write=False) - result = pd.Series(arr).rolling(2).mean() - expected = pd.Series([np.nan, 2, np.nan, np.nan, 4]) + result = Series(arr).rolling(2).mean() + expected = Series([np.nan, 2, np.nan, np.nan, 4]) tm.assert_series_equal(result, expected) @@ -442,7 +440,7 @@ def test_min_periods1(): # GH#6795 df = pd.DataFrame([0, 1, 2, 1, 0], columns=["a"]) result = df["a"].rolling(3, center=True, min_periods=1).max() - expected = pd.Series([1.0, 2.0, 2.0, 2.0, 1.0], name="a") + expected = Series([1.0, 2.0, 2.0, 2.0, 1.0], name="a") tm.assert_series_equal(result, expected) @@ -741,7 +739,7 @@ def test_rolling_numerical_accuracy_kahan_sum(): # GH: 13254 df = pd.DataFrame([2.186, -1.647, 0.0, 0.0, 0.0, 0.0], columns=["x"]) result = df["x"].rolling(3).sum() - expected = pd.Series([np.nan, np.nan, 0.539, -1.647, 0.0, 0.0], name="x") + expected = Series([np.nan, np.nan, 0.539, -1.647, 0.0, 0.0], name="x") tm.assert_series_equal(result, expected) @@ -770,10 +768,10 @@ def test_rolling_numerical_accuracy_small_values(): def test_rolling_numerical_too_large_numbers(): # GH: 11645 dates = pd.date_range("2015-01-01", periods=10, freq="D") - ds = pd.Series(data=range(10), index=dates, dtype=np.float64) + ds = Series(data=range(10), index=dates, dtype=np.float64) ds[2] = -9e33 result = ds.rolling(5).mean() - expected = pd.Series( + expected = Series( [np.nan, np.nan, np.nan, np.nan, -1.8e33, -1.8e33, -1.8e33, 5.0, 6.0, 7.0], index=dates, ) @@ -864,9 +862,9 @@ def test_rolling_on_df_transposed(): ) def test_rolling_period_index(index, window, func, values): # GH: 34225 - ds = pd.Series([0, 1, 2, 3, 4, 5, 6, 7, 8], index=index) + ds = Series([0, 1, 2, 3, 4, 5, 6, 7, 8], index=index) result = getattr(ds.rolling(window, closed="left"), func)() - expected = pd.Series(values, index=index) + expected = Series(values, index=index) tm.assert_series_equal(result, expected) @@ -876,8 +874,8 @@ def test_rolling_sem(constructor): obj = getattr(pd, constructor)([0, 1, 2]) result = obj.rolling(2, min_periods=1).sem() if isinstance(result, DataFrame): - result = pd.Series(result[0].values) - expected = pd.Series([np.nan] + [0.707107] * 2) + result = Series(result[0].values) + expected = Series([np.nan] + [0.707107] * 2) tm.assert_series_equal(result, expected) @@ -892,7 +890,7 @@ def test_rolling_sem(constructor): ) def test_rolling_var_numerical_issues(func, third_value, values): # GH: 37051 - ds = pd.Series([99999999999999999, 1, third_value, 2, 3, 1, 1]) + ds = Series([99999999999999999, 1, third_value, 2, 3, 1, 1]) result = getattr(ds.rolling(2), func)() - expected = pd.Series([np.nan] + values) + expected = Series([np.nan] + values) tm.assert_series_equal(result, expected)