Skip to content

Commit

Permalink
fixed a bunch of failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SaturnFromTitan committed Nov 5, 2019
1 parent f5ed452 commit c761bab
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
18 changes: 9 additions & 9 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_nunique_empty(self):
tm.assert_series_equal(result, expected)

result = df.T.nunique()
expected = Series([], index=pd.Index([]))
expected = Series(index=pd.Index([]), dtype=np.float64)
tm.assert_series_equal(result, expected)

def test_apply_standard_nonunique(self):
Expand Down Expand Up @@ -1268,16 +1268,16 @@ def test_non_callable_aggregates(self):
_get_cython_table_params(
DataFrame(),
[
("sum", Series()),
("max", Series()),
("min", Series()),
("sum", Series(dtype="float64")),
("max", Series(dtype="float64")),
("min", Series(dtype="float64")),
("all", Series(dtype=bool)),
("any", Series(dtype=bool)),
("mean", Series()),
("prod", Series()),
("std", Series()),
("var", Series()),
("median", Series()),
("mean", Series(dtype="float64")),
("prod", Series(dtype="float64")),
("std", Series(dtype="float64")),
("var", Series(dtype="float64")),
("median", Series(dtype="float64")),
],
),
_get_cython_table_params(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,7 @@ def test_from_records_series_list_dict(self):
def test_to_frame_with_falsey_names(self):
# GH 16114
result = Series(name=0).to_frame().dtypes
expected = Series({0: np.float64})
expected = Series({0: object})
tm.assert_series_equal(result, expected)

result = DataFrame(Series(name=0)).dtypes
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,9 @@ def test_xs_corner(self):
# no columns but Index(dtype=object)
df = DataFrame(index=["a", "b", "c"])
result = df.xs("a")
expected = Series([], name="a", index=pd.Index([], dtype=object))
expected = Series(
[], name="a", index=pd.Index([], dtype=object), dtype="float64"
)
tm.assert_series_equal(result, expected)

def test_xs_duplicates(self):
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,8 @@ def test_squeeze(self):
# don't fail with 0 length dimensions GH11229 & GH8999
empty_series = Series([], name="five")
empty_frame = DataFrame([empty_series])

[
tm.assert_series_equal(empty_series, higher_dim.squeeze())
for higher_dim in [empty_series, empty_frame]
]
tm.assert_series_equal(empty_series, empty_series.squeeze())
tm.assert_series_equal(empty_series, empty_frame.squeeze())

# axis argument
df = tm.makeTimeDataFrame(nper=1).iloc[:, :1]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def test_evaluate_with_empty_groups(self, func, expected):

def test_groupby_empty(self):
# https://github.com/pandas-dev/pandas/issues/27190
s = pd.Series([], name="name")
s = pd.Series(name="name", dtype="float64")
gr = s.groupby([])

result = gr.mean()
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/indexing/multiindex/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def test_loc_getitem_series(self):

empty = Series(data=[], dtype=np.float64)
expected = Series(
[], index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64)
[],
index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64),
dtype=np.float64,
)
result = x.loc[empty]
tm.assert_series_equal(result, expected)
Expand All @@ -72,7 +74,9 @@ def test_loc_getitem_array(self):
# empty array:
empty = np.array([])
expected = Series(
[], index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64)
[],
index=MultiIndex(levels=index.levels, codes=[[], []], dtype=np.float64),
dtype="float64",
)
result = x.loc[empty]
tm.assert_series_equal(result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def test_series_roundtrip_object(self, orient, numpy, dtype):
def test_series_roundtrip_empty(self, orient, numpy):
data = self.empty_series.to_json(orient=orient)
result = pd.read_json(data, typ="series", orient=orient, numpy=numpy)
expected = self.empty_series.copy()
expected = self.empty_series.copy().astype("float64")

# TODO: see what causes inconsistency
if not numpy and PY35 and orient == "index":
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/reductions/test_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def test_timedelta64_analytics(self):
@pytest.mark.parametrize(
"test_input,error_type",
[
(pd.Series([]), ValueError),
(pd.Series(dtype="float64"), ValueError),
# For strings, or any Series with dtype 'O'
(pd.Series(["foo", "bar", "baz"]), TypeError),
(pd.Series([(1,), (2,)]), TypeError),
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ def test_concat_period_other_series(self):
def test_concat_empty_series(self):
# GH 11082
s1 = pd.Series([1, 2, 3], name="x")
s2 = pd.Series(name="y")
s2 = pd.Series(name="y", dtype="float64")
res = pd.concat([s1, s2], axis=1)
exp = pd.DataFrame(
{"x": [1, 2, 3], "y": [np.nan, np.nan, np.nan]},
Expand All @@ -2205,15 +2205,15 @@ def test_concat_empty_series(self):
tm.assert_frame_equal(res, exp)

s1 = pd.Series([1, 2, 3], name="x")
s2 = pd.Series(name="y")
s2 = pd.Series(name="y", dtype="float64")
res = pd.concat([s1, s2], axis=0)
# name will be reset
exp = pd.Series([1, 2, 3])
tm.assert_series_equal(res, exp)

# empty Series with no name
s1 = pd.Series([1, 2, 3], name="x")
s2 = pd.Series(name=None)
s2 = pd.Series(name=None, dtype="float64")
res = pd.concat([s1, s2], axis=1)
exp = pd.DataFrame(
{"x": [1, 2, 3], 0: [np.nan, np.nan, np.nan]},
Expand All @@ -2228,7 +2228,7 @@ def test_concat_empty_series_timelike(self, tz, values):
# GH 18447

first = Series([], dtype="M8[ns]").dt.tz_localize(tz)
second = Series(values)
second = Series(values, dtype="float64")
expected = DataFrame(
{
0: pd.Series([pd.NaT] * len(values), dtype="M8[ns]").dt.tz_localize(tz),
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/window/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def f(x):

self._check_moment_func(np.mean, name="apply", func=f, raw=raw)

expected = Series([])
expected = Series(dtype="float64")
result = expected.rolling(10).apply(lambda x: x.mean(), raw=raw)
tm.assert_series_equal(result, expected)

Expand Down Expand Up @@ -1170,7 +1170,7 @@ def _check_ew(self, name=None, preserve_nan=False):

# check series of length 0
result = getattr(Series().ewm(com=50, min_periods=min_periods), name)()
tm.assert_series_equal(result, Series())
tm.assert_series_equal(result, Series(dtype="float64"))

# check series of length 1
result = getattr(Series([1.0]).ewm(50, min_periods=min_periods), name)()
Expand Down Expand Up @@ -1965,8 +1965,8 @@ def func(A, B, com, **kwargs):
assert not np.isnan(result.values[11:]).any()

# check series of length 0
result = func(Series([]), Series([]), 50, min_periods=min_periods)
tm.assert_series_equal(result, Series([]))
result = func(Series(), Series(), 50, min_periods=min_periods)
tm.assert_series_equal(result, Series(dtype="float64"))

# check series of length 1
result = func(Series([1.0]), Series([1.0]), 50, min_periods=min_periods)
Expand Down Expand Up @@ -2166,7 +2166,7 @@ def test_rolling_functions_window_non_shrinkage_binary(self):

def test_moment_functions_zero_length(self):
# GH 8056
s = Series()
s = Series(dtype="float64")
s_expected = s
df1 = DataFrame()
df1_expected = df1
Expand Down Expand Up @@ -2385,7 +2385,7 @@ def expanding_mean(x, min_periods=1):
# here to make this pass
self._check_expanding(expanding_mean, np.mean, preserve_nan=False)

ser = Series([])
ser = Series([], dtype="float64")
tm.assert_series_equal(ser, ser.expanding().apply(lambda x: x.mean(), raw=raw))

# GH 8080
Expand Down

0 comments on commit c761bab

Please sign in to comment.