Skip to content

Commit 35ad2bb

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
TST/REF: collect tests by method (pandas-dev#37315)
1 parent 0a265b6 commit 35ad2bb

File tree

5 files changed

+92
-92
lines changed

5 files changed

+92
-92
lines changed

pandas/tests/frame/methods/test_values.py

+52-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22

3-
from pandas import DataFrame, Timestamp, date_range
3+
from pandas import DataFrame, NaT, Timestamp, date_range
44
import pandas._testing as tm
55

66

@@ -51,3 +51,54 @@ def test_frame_values_with_tz(self):
5151
expected = np.concatenate([expected, new], axis=1)
5252
result = df.values
5353
tm.assert_numpy_array_equal(result, expected)
54+
55+
def test_interleave_with_tzaware(self, timezone_frame):
56+
57+
# interleave with object
58+
result = timezone_frame.assign(D="foo").values
59+
expected = np.array(
60+
[
61+
[
62+
Timestamp("2013-01-01 00:00:00"),
63+
Timestamp("2013-01-02 00:00:00"),
64+
Timestamp("2013-01-03 00:00:00"),
65+
],
66+
[
67+
Timestamp("2013-01-01 00:00:00-0500", tz="US/Eastern"),
68+
NaT,
69+
Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern"),
70+
],
71+
[
72+
Timestamp("2013-01-01 00:00:00+0100", tz="CET"),
73+
NaT,
74+
Timestamp("2013-01-03 00:00:00+0100", tz="CET"),
75+
],
76+
["foo", "foo", "foo"],
77+
],
78+
dtype=object,
79+
).T
80+
tm.assert_numpy_array_equal(result, expected)
81+
82+
# interleave with only datetime64[ns]
83+
result = timezone_frame.values
84+
expected = np.array(
85+
[
86+
[
87+
Timestamp("2013-01-01 00:00:00"),
88+
Timestamp("2013-01-02 00:00:00"),
89+
Timestamp("2013-01-03 00:00:00"),
90+
],
91+
[
92+
Timestamp("2013-01-01 00:00:00-0500", tz="US/Eastern"),
93+
NaT,
94+
Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern"),
95+
],
96+
[
97+
Timestamp("2013-01-01 00:00:00+0100", tz="CET"),
98+
NaT,
99+
Timestamp("2013-01-03 00:00:00+0100", tz="CET"),
100+
],
101+
],
102+
dtype=object,
103+
).T
104+
tm.assert_numpy_array_equal(result, expected)

pandas/tests/frame/test_dtypes.py

+1-70
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pandas.core.dtypes.dtypes import DatetimeTZDtype
77

88
import pandas as pd
9-
from pandas import DataFrame, Series, Timestamp, date_range, option_context
9+
from pandas import DataFrame, Series, date_range, option_context
1010
import pandas._testing as tm
1111

1212

@@ -18,22 +18,6 @@ def _check_cast(df, v):
1818

1919

2020
class TestDataFrameDataTypes:
21-
def test_concat_empty_dataframe_dtypes(self):
22-
df = DataFrame(columns=list("abc"))
23-
df["a"] = df["a"].astype(np.bool_)
24-
df["b"] = df["b"].astype(np.int32)
25-
df["c"] = df["c"].astype(np.float64)
26-
27-
result = pd.concat([df, df])
28-
assert result["a"].dtype == np.bool_
29-
assert result["b"].dtype == np.int32
30-
assert result["c"].dtype == np.float64
31-
32-
result = pd.concat([df, df.astype(np.float64)])
33-
assert result["a"].dtype == np.object_
34-
assert result["b"].dtype == np.float64
35-
assert result["c"].dtype == np.float64
36-
3721
def test_empty_frame_dtypes(self):
3822
empty_df = DataFrame()
3923
tm.assert_series_equal(empty_df.dtypes, Series(dtype=object))
@@ -244,56 +228,3 @@ def test_str_to_small_float_conversion_type(self):
244228
result.loc[result.index, "A"] = [float(x) for x in col_data]
245229
expected = DataFrame(col_data, columns=["A"], dtype=float)
246230
tm.assert_frame_equal(result, expected)
247-
248-
249-
class TestDataFrameDatetimeWithTZ:
250-
def test_interleave(self, timezone_frame):
251-
252-
# interleave with object
253-
result = timezone_frame.assign(D="foo").values
254-
expected = np.array(
255-
[
256-
[
257-
Timestamp("2013-01-01 00:00:00"),
258-
Timestamp("2013-01-02 00:00:00"),
259-
Timestamp("2013-01-03 00:00:00"),
260-
],
261-
[
262-
Timestamp("2013-01-01 00:00:00-0500", tz="US/Eastern"),
263-
pd.NaT,
264-
Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern"),
265-
],
266-
[
267-
Timestamp("2013-01-01 00:00:00+0100", tz="CET"),
268-
pd.NaT,
269-
Timestamp("2013-01-03 00:00:00+0100", tz="CET"),
270-
],
271-
["foo", "foo", "foo"],
272-
],
273-
dtype=object,
274-
).T
275-
tm.assert_numpy_array_equal(result, expected)
276-
277-
# interleave with only datetime64[ns]
278-
result = timezone_frame.values
279-
expected = np.array(
280-
[
281-
[
282-
Timestamp("2013-01-01 00:00:00"),
283-
Timestamp("2013-01-02 00:00:00"),
284-
Timestamp("2013-01-03 00:00:00"),
285-
],
286-
[
287-
Timestamp("2013-01-01 00:00:00-0500", tz="US/Eastern"),
288-
pd.NaT,
289-
Timestamp("2013-01-03 00:00:00-0500", tz="US/Eastern"),
290-
],
291-
[
292-
Timestamp("2013-01-01 00:00:00+0100", tz="CET"),
293-
pd.NaT,
294-
Timestamp("2013-01-03 00:00:00+0100", tz="CET"),
295-
],
296-
],
297-
dtype=object,
298-
).T
299-
tm.assert_numpy_array_equal(result, expected)

pandas/tests/reshape/test_concat.py

+16
Original file line numberDiff line numberDiff line change
@@ -2604,6 +2604,22 @@ def test_concat_odered_dict(self):
26042604
)
26052605
tm.assert_series_equal(result, expected)
26062606

2607+
def test_concat_empty_dataframe_dtypes(self):
2608+
df = DataFrame(columns=list("abc"))
2609+
df["a"] = df["a"].astype(np.bool_)
2610+
df["b"] = df["b"].astype(np.int32)
2611+
df["c"] = df["c"].astype(np.float64)
2612+
2613+
result = pd.concat([df, df])
2614+
assert result["a"].dtype == np.bool_
2615+
assert result["b"].dtype == np.int32
2616+
assert result["c"].dtype == np.float64
2617+
2618+
result = pd.concat([df, df.astype(np.float64)])
2619+
assert result["a"].dtype == np.object_
2620+
assert result["b"].dtype == np.float64
2621+
assert result["c"].dtype == np.float64
2622+
26072623

26082624
@pytest.mark.parametrize("pdt", [Series, pd.DataFrame])
26092625
@pytest.mark.parametrize("dt", np.sctypes["float"])

pandas/tests/series/indexing/test_setitem.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
from datetime import date
2+
13
import numpy as np
24
import pytest
35

4-
from pandas import MultiIndex, NaT, Series, date_range, period_range
6+
from pandas import MultiIndex, NaT, Series, Timestamp, date_range, period_range
57
import pandas.testing as tm
68

79

@@ -28,6 +30,26 @@ def test_setitem_multiindex_empty_slice(self):
2830
result.loc[[]] = 0
2931
tm.assert_series_equal(result, expected)
3032

33+
def test_setitem_with_string_index(self):
34+
# GH#23451
35+
ser = Series([1, 2, 3], index=["Date", "b", "other"])
36+
ser["Date"] = date.today()
37+
assert ser.Date == date.today()
38+
assert ser["Date"] == date.today()
39+
40+
def test_setitem_with_different_tz_casts_to_object(self):
41+
# GH#24024
42+
ser = Series(date_range("2000", periods=2, tz="US/Central"))
43+
ser[0] = Timestamp("2000", tz="US/Eastern")
44+
expected = Series(
45+
[
46+
Timestamp("2000-01-01 00:00:00-05:00", tz="US/Eastern"),
47+
Timestamp("2000-01-02 00:00:00-06:00", tz="US/Central"),
48+
],
49+
dtype=object,
50+
)
51+
tm.assert_series_equal(ser, expected)
52+
3153

3254
class TestSetitemPeriodDtype:
3355
@pytest.mark.parametrize("na_val", [None, np.nan])

pandas/tests/series/test_datetime_values.py renamed to pandas/tests/series/test_dt_accessor.py

-20
Original file line numberDiff line numberDiff line change
@@ -655,26 +655,6 @@ def test_dt_timetz_accessor(self, tz_naive_fixture):
655655
result = s.dt.timetz
656656
tm.assert_series_equal(result, expected)
657657

658-
def test_setitem_with_string_index(self):
659-
# GH 23451
660-
x = Series([1, 2, 3], index=["Date", "b", "other"])
661-
x["Date"] = date.today()
662-
assert x.Date == date.today()
663-
assert x["Date"] == date.today()
664-
665-
def test_setitem_with_different_tz(self):
666-
# GH#24024
667-
ser = Series(pd.date_range("2000", periods=2, tz="US/Central"))
668-
ser[0] = pd.Timestamp("2000", tz="US/Eastern")
669-
expected = Series(
670-
[
671-
pd.Timestamp("2000-01-01 00:00:00-05:00", tz="US/Eastern"),
672-
pd.Timestamp("2000-01-02 00:00:00-06:00", tz="US/Central"),
673-
],
674-
dtype=object,
675-
)
676-
tm.assert_series_equal(ser, expected)
677-
678658
@pytest.mark.parametrize(
679659
"input_series, expected_output",
680660
[

0 commit comments

Comments
 (0)