Skip to content

TST: More regression tests #31196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,36 @@ def test_read_excel_parse_dates(self, ext):
)
tm.assert_frame_equal(df, res)

def test_multiindex_interval_datetimes(self, ext):
# GH 30986
midx = pd.MultiIndex.from_arrays(
[
range(4),
pd.interval_range(
start=pd.Timestamp("2020-01-01"), periods=4, freq="6M"
),
]
)
df = pd.DataFrame(range(4), index=midx)
with tm.ensure_clean(ext) as pth:
df.to_excel(pth)
result = pd.read_excel(pth, index_col=[0, 1])
expected = pd.DataFrame(
range(4),
pd.MultiIndex.from_arrays(
[
range(4),
[
"(2020-01-31, 2020-07-31]",
"(2020-07-31, 2021-01-31]",
"(2021-01-31, 2021-07-31]",
"(2021-07-31, 2022-01-31]",
],
]
),
)
tm.assert_frame_equal(result, expected)


@td.skip_if_no("xlrd")
@pytest.mark.parametrize(
Expand Down
23 changes: 22 additions & 1 deletion pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

from pandas import DataFrame, Index, json_normalize
from pandas import DataFrame, Index, Series, json_normalize
import pandas._testing as tm

from pandas.io.json._normalize import nested_to_record
Expand Down Expand Up @@ -728,3 +728,24 @@ def test_deprecated_import(self):

recs = [{"a": 1, "b": 2, "c": 3}, {"a": 4, "b": 5, "c": 6}]
json_normalize(recs)

def test_series_non_zero_index(self):
# GH 19020
data = {
0: {"id": 1, "name": "Foo", "elements": {"a": 1}},
1: {"id": 2, "name": "Bar", "elements": {"b": 2}},
2: {"id": 3, "name": "Baz", "elements": {"c": 3}},
}
s = Series(data)
s.index = [1, 2, 3]
result = json_normalize(s)
expected = DataFrame(
{
"id": [1, 2, 3],
"name": ["Foo", "Bar", "Baz"],
"elements.a": [1.0, np.nan, np.nan],
"elements.b": [np.nan, 2.0, np.nan],
"elements.c": [np.nan, np.nan, 3.0],
}
)
tm.assert_frame_equal(result, expected)
12 changes: 12 additions & 0 deletions pandas/tests/resample/test_period_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,15 @@ def test_get_period_range_edges(self, first, last, offset, exp_first, exp_last):
result = _get_period_range_edges(first, last, offset)
expected = (exp_first, exp_last)
assert result == expected

def test_sum_min_count(self):
# GH 19974
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()
result = s.resample("Q").sum(min_count=1)
expected = pd.Series(
[3.0, np.nan], index=PeriodIndex(["2018Q1", "2018Q2"], freq="Q-DEC")
)
tm.assert_series_equal(result, expected)
25 changes: 25 additions & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,31 @@ def manual_compare_stacked(df, df_stacked, lev0, lev1):
)
manual_compare_stacked(df, df.stack(0), 0, 1)

def test_stack_unstack_unordered_multiindex(self):
# GH 18265
values = np.arange(5)
data = np.vstack(
[
["b{}".format(x) for x in values], # b0, b1, ..
["a{}".format(x) for x in values],
]
) # a0, a1, ..
df = pd.DataFrame(data.T, columns=["b", "a"])
df.columns.name = "first"
second_level_dict = {"x": df}
multi_level_df = pd.concat(second_level_dict, axis=1)
multi_level_df.columns.names = ["second", "first"]
df = multi_level_df.reindex(sorted(multi_level_df.columns), axis=1)
result = df.stack(["first", "second"]).unstack(["first", "second"])
expected = DataFrame(
[["a0", "b0"], ["a1", "b1"], ["a2", "b2"], ["a3", "b3"], ["a4", "b4"]],
index=[0, 1, 2, 3, 4],
columns=MultiIndex.from_tuples(
[("a", "x"), ("b", "x")], names=["first", "second"]
),
)
tm.assert_frame_equal(result, expected)

def test_groupby_corner(self):
midx = MultiIndex(
levels=[["foo"], ["bar"], ["baz"]],
Expand Down