Skip to content

TST: tests for needs-test issues #30222

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 4 commits into from
Dec 12, 2019
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
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,14 @@ def test_filter_corner(self):
result = empty.filter(like="foo")
tm.assert_frame_equal(result, empty)

def test_filter_regex_non_string(self):
# GH#5798 trying to filter on non-string columns should drop,
# not raise
df = pd.DataFrame(np.random.random((3, 2)), columns=["STRING", 123])
result = df.filter(regex="STRING")
expected = df[["STRING"]]
tm.assert_frame_equal(result, expected)

def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
Expand Down
8 changes: 7 additions & 1 deletion pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,16 @@ def test_constructor_with_datetimes(self):
tm.assert_frame_equal(df, expected)

def test_constructor_datetimes_with_nulls(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can parameterize (later ok too)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel : do you plan on addressing this here or later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

later

# gh-15869
# gh-15869, GH#11220
for arr in [
np.array([None, None, None, None, datetime.now(), None]),
np.array([None, None, datetime.now(), None]),
[[np.datetime64("NaT")], [None]],
[[np.datetime64("NaT")], [pd.NaT]],
[[None], [np.datetime64("NaT")]],
[[None], [pd.NaT]],
[[pd.NaT], [np.datetime64("NaT")]],
[[pd.NaT], [None]],
]:
result = DataFrame(arr).dtypes
expected = Series([np.dtype("datetime64[ns]")])
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/frame/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@


class TestDataFrameQuantile:
def test_quantile_sparse(self):
# GH#17198
s = pd.Series(pd.SparseArray([1, 2]))
s1 = pd.Series(pd.SparseArray([3, 4]))
df = pd.DataFrame({0: s, 1: s1})
result = df.quantile()

expected = pd.Series([1.5, 3.5], name=0.5)
tm.assert_series_equal(result, expected)

def test_quantile(self, datetime_frame):
from numpy import percentile

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,14 @@ def test_first_last_valid(
assert expected_first == df.first_valid_index()
assert expected_last == df.last_valid_index()

@pytest.mark.parametrize("klass", [Series, DataFrame])
def test_first_valid_index_all_nan(self, klass):
# GH#9752 Series/DataFrame should both return None, not raise
obj = klass([np.nan])

assert obj.first_valid_index() is None
assert obj.iloc[:0].first_valid_index() is None

def test_first_subset(self):
ts = tm.makeTimeDataFrame(freq="12h")
result = ts.first("10d")
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/indexes/multi/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,17 @@ def test_from_product_respects_none_names():
tm.assert_index_equal(result, expected)


def test_from_product_readonly():
# GH#15286 passing read-only array to from_product
a = np.array(range(3))
b = ["a", "b"]
expected = MultiIndex.from_product([a, b])

a.setflags(write=False)
result = MultiIndex.from_product([a, b])
tm.assert_index_equal(result, expected)


def test_create_index_existing_name(idx):

# GH11193, when an existing index is passed, and a new name is not
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,15 @@ def test_truncate_with_different_dtypes(self):
assert "None" in result
assert "NaN" not in result

def test_truncate_with_different_dtypes_multiindex(self):
# GH#13000
df = DataFrame({"Vals": range(100)})
frame = pd.concat([df], keys=["Sweep"], names=["Sweep", "Index"])
result = repr(frame)

result2 = repr(frame.iloc[:5])
assert result.startswith(result2)

def test_datetimelike_frame(self):

# GH 12211
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ def test_fillna_consistency(self):
s2[1] = "foo"
tm.assert_series_equal(s2, expected)

def test_where_sparse(self):
# GH#17198 make sure we dont get an AttributeError for sp_index
ser = pd.Series(pd.SparseArray([1, 2]))
result = ser.where(ser >= 2, 0)
expected = pd.Series(pd.SparseArray([0, 2]))
tm.assert_series_equal(result, expected)

def test_datetime64tz_fillna_round_issue(self):
# GH 14872

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/window/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,11 @@ def test_rolling_window_as_string():

expected = Series(expData, index=Index(days, name="DateCol"), name="metric")
tm.assert_series_equal(result, expected)


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")
tm.assert_series_equal(result, expected)