Skip to content

Commit 615eadf

Browse files
authored
TST: Old issues (#41607)
1 parent 85f4878 commit 615eadf

File tree

7 files changed

+99
-1
lines changed

7 files changed

+99
-1
lines changed

pandas/tests/frame/indexing/test_where.py

+12
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,15 @@ def test_where_bool_comparison():
745745
}
746746
)
747747
tm.assert_frame_equal(result, expected)
748+
749+
750+
def test_where_none_nan_coerce():
751+
# GH 15613
752+
expected = DataFrame(
753+
{
754+
"A": [Timestamp("20130101"), pd.NaT, Timestamp("20130103")],
755+
"B": [1, 2, np.nan],
756+
}
757+
)
758+
result = expected.where(expected.notnull(), None)
759+
tm.assert_frame_equal(result, expected)

pandas/tests/frame/methods/test_to_csv.py

+11
Original file line numberDiff line numberDiff line change
@@ -1330,3 +1330,14 @@ def test_to_csv_numpy_16_bug(self):
13301330

13311331
result = buf.getvalue()
13321332
assert "2000-01-01" in result
1333+
1334+
def test_to_csv_na_quoting(self):
1335+
# GH 15891
1336+
# Normalize carriage return for Windows OS
1337+
result = (
1338+
DataFrame([None, None])
1339+
.to_csv(None, header=False, index=False, na_rep="")
1340+
.replace("\r\n", "\n")
1341+
)
1342+
expected = '""\n""\n'
1343+
assert result == expected

pandas/tests/groupby/test_groupby.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ def test_index_label_overlaps_location():
16571657
expected = ser.take([1, 3, 4])
16581658
tm.assert_series_equal(actual, expected)
16591659

1660-
# ... and again, with a generic Index of floats
1660+
# and again, with a generic Index of floats
16611661
df.index = df.index.astype(float)
16621662
g = df.groupby(list("ababb"))
16631663
actual = g.filter(lambda x: len(x) > 2)
@@ -2283,3 +2283,23 @@ def test_groupby_empty_multi_column():
22832283
[], columns=["C"], index=MultiIndex([[], []], [[], []], names=["A", "B"])
22842284
)
22852285
tm.assert_frame_equal(result, expected)
2286+
2287+
2288+
def test_groupby_filtered_df_std():
2289+
# GH 16174
2290+
dicts = [
2291+
{"filter_col": False, "groupby_col": True, "bool_col": True, "float_col": 10.5},
2292+
{"filter_col": True, "groupby_col": True, "bool_col": True, "float_col": 20.5},
2293+
{"filter_col": True, "groupby_col": True, "bool_col": True, "float_col": 30.5},
2294+
]
2295+
df = DataFrame(dicts)
2296+
2297+
df_filter = df[df["filter_col"] == True] # noqa:E712
2298+
dfgb = df_filter.groupby("groupby_col")
2299+
result = dfgb.std()
2300+
expected = DataFrame(
2301+
[[0.0, 0.0, 7.071068]],
2302+
columns=["filter_col", "bool_col", "float_col"],
2303+
index=Index([True], name="groupby_col"),
2304+
)
2305+
tm.assert_frame_equal(result, expected)

pandas/tests/indexing/multiindex/test_loc.py

+30
Original file line numberDiff line numberDiff line change
@@ -801,3 +801,33 @@ def test_mi_partial_indexing_list_raises():
801801
frame.columns.names = ["state", "color"]
802802
with pytest.raises(KeyError, match="\\[2\\] not in index"):
803803
frame.loc[["b", 2], "Colorado"]
804+
805+
806+
def test_mi_indexing_list_nonexistent_raises():
807+
# GH 15452
808+
s = Series(range(4), index=MultiIndex.from_product([[1, 2], ["a", "b"]]))
809+
with pytest.raises(KeyError, match="\\['not' 'found'\\] not in index"):
810+
s.loc[["not", "found"]]
811+
812+
813+
def test_mi_add_cell_missing_row_non_unique():
814+
# GH 16018
815+
result = DataFrame(
816+
[[1, 2, 5, 6], [3, 4, 7, 8]],
817+
index=["a", "a"],
818+
columns=MultiIndex.from_product([[1, 2], ["A", "B"]]),
819+
)
820+
result.loc["c"] = -1
821+
result.loc["c", (1, "A")] = 3
822+
result.loc["d", (1, "A")] = 3
823+
expected = DataFrame(
824+
[
825+
[1.0, 2.0, 5.0, 6.0],
826+
[3.0, 4.0, 7.0, 8.0],
827+
[3.0, -1.0, -1, -1],
828+
[3.0, np.nan, np.nan, np.nan],
829+
],
830+
index=["a", "a", "c", "d"],
831+
columns=MultiIndex.from_product([[1, 2], ["A", "B"]]),
832+
)
833+
tm.assert_frame_equal(result, expected)

pandas/tests/indexing/test_loc.py

+11
Original file line numberDiff line numberDiff line change
@@ -2684,3 +2684,14 @@ def test_loc_assign_dict_to_row(self, dtype):
26842684
expected = DataFrame({"A": ["newA", "def"], "B": ["newB", "jkl"]}, dtype=dtype)
26852685

26862686
tm.assert_frame_equal(df, expected)
2687+
2688+
@td.skip_array_manager_invalid_test
2689+
def test_loc_setitem_dict_timedelta_multiple_set(self):
2690+
# GH 16309
2691+
result = DataFrame(columns=["time", "value"])
2692+
result.loc[1] = {"time": Timedelta(6, unit="s"), "value": "foo"}
2693+
result.loc[1] = {"time": Timedelta(6, unit="s"), "value": "foo"}
2694+
expected = DataFrame(
2695+
[[Timedelta(6, unit="s"), "foo"]], columns=["time", "value"], index=[1]
2696+
)
2697+
tm.assert_frame_equal(result, expected)

pandas/tests/scalar/timestamp/test_constructors.py

+7
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ def test_bounds_with_different_units(self):
437437
dt64 = np.datetime64(date_string, unit)
438438
Timestamp(dt64)
439439

440+
@pytest.mark.parametrize("arg", ["001-01-01", "0001-01-01"])
441+
def test_out_of_bounds_string_consistency(self, arg):
442+
# GH 15829
443+
msg = "Out of bounds"
444+
with pytest.raises(OutOfBoundsDatetime, match=msg):
445+
Timestamp(arg)
446+
440447
def test_min_valid(self):
441448
# Ensure that Timestamp.min is a valid Timestamp
442449
Timestamp(Timestamp.min)

pandas/tests/tools/test_to_numeric.py

+7
Original file line numberDiff line numberDiff line change
@@ -780,3 +780,10 @@ def test_downcast_nullable_mask_is_copied():
780780

781781
arr[1] = pd.NA # should not modify result
782782
tm.assert_extension_array_equal(result, expected)
783+
784+
785+
def test_to_numeric_scientific_notation():
786+
# GH 15898
787+
result = to_numeric("1.7e+308")
788+
expected = np.float64(1.7e308)
789+
assert result == expected

0 commit comments

Comments
 (0)