We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cdffa43 commit bbcda98Copy full SHA for bbcda98
pandas/tests/frame/test_constructors.py
@@ -2433,6 +2433,24 @@ def test_datetime_date_tuple_columns_from_dict(self):
2433
expected = DataFrame([0, 1, 2], columns=pd.Index(pd.Series([tup])))
2434
tm.assert_frame_equal(result, expected)
2435
2436
+ def test_construct_with_two_categoricalindex_series(self):
2437
+ # GH 14600
2438
+ s1 = pd.Series(
2439
+ [39, 6, 4], index=pd.CategoricalIndex(["female", "male", "unknown"])
2440
+ )
2441
+ s2 = pd.Series(
2442
+ [2, 152, 2, 242, 150],
2443
+ index=pd.CategoricalIndex(["f", "female", "m", "male", "unknown"]),
2444
2445
+ result = pd.DataFrame([s1, s2])
2446
+ expected = pd.DataFrame(
2447
+ np.array(
2448
+ [[np.nan, 39.0, np.nan, 6.0, 4.0], [2.0, 152.0, 2.0, 242.0, 150.0]]
2449
+ ),
2450
+ columns=["f", "female", "m", "male", "unknown"],
2451
2452
+ tm.assert_frame_equal(result, expected)
2453
+
2454
2455
class TestDataFrameConstructorWithDatetimeTZ:
2456
def test_from_dict(self):
pandas/tests/groupby/test_apply.py
@@ -792,3 +792,22 @@ def test_apply_multi_level_name(category):
792
)
793
794
assert df.index.names == ["A", "B"]
795
796
797
+def test_groupby_apply_datetime_result_dtypes():
798
+ # GH 14849
799
+ data = pd.DataFrame.from_records(
800
+ [
801
+ (pd.Timestamp(2016, 1, 1), "red", "dark", 1, "8"),
802
+ (pd.Timestamp(2015, 1, 1), "green", "stormy", 2, "9"),
803
+ (pd.Timestamp(2014, 1, 1), "blue", "bright", 3, "10"),
804
+ (pd.Timestamp(2013, 1, 1), "blue", "calm", 4, "potato"),
805
+ ],
806
+ columns=["observation", "color", "mood", "intensity", "score"],
807
808
+ result = data.groupby("color").apply(lambda g: g.iloc[0]).dtypes
809
+ expected = Series(
810
+ [np.dtype("datetime64[ns]"), np.object, np.object, np.int64, np.object],
811
+ index=["observation", "color", "mood", "intensity", "score"],
812
813
+ tm.assert_series_equal(result, expected)
pandas/tests/groupby/test_groupby.py
@@ -1952,6 +1952,13 @@ def test_shift_bfill_ffill_tz(tz_naive_fixture, op, expected):
1952
1953
1954
1955
+def test_ffill_missing_arguments():
1956
+ # GH 14955
1957
+ df = pd.DataFrame({"a": [1, 2], "b": [1, 1]})
1958
+ with pytest.raises(ValueError, match="Must specify a fill"):
1959
+ df.groupby("b").fillna()
1960
1961
1962
def test_groupby_only_none_group():
1963
# see GH21624
1964
# this was crashing with "ValueError: Length of passed values is 1, index implies 0"
pandas/tests/indexing/test_loc.py
@@ -1002,3 +1002,13 @@ def test_loc_axis_1_slice():
1002
),
1003
1004
1005
1006
1007
+def test_loc_set_dataframe_multiindex():
1008
+ # GH 14592
1009
1010
+ "a", index=range(2), columns=pd.MultiIndex.from_product([range(2), range(2)])
1011
1012
+ result = expected.copy()
1013
+ result.loc[0, [(0, 1)]] = result.loc[0, [(0, 1)]]
1014
pandas/tests/io/test_pickle.py
@@ -11,6 +11,7 @@
11
3. Move the created pickle to "data/legacy_pickle/<version>" directory.
12
"""
13
import bz2
14
+import datetime
15
import glob
16
import gzip
17
import os
@@ -487,3 +488,17 @@ def open(self, *args):
487
488
df.to_pickle(mockurl)
489
result = pd.read_pickle(mockurl)
490
tm.assert_frame_equal(df, result)
491
492
493
+class MyTz(datetime.tzinfo):
494
+ def __init__(self):
495
+ pass
496
497
498
+def test_read_pickle_with_subclass():
499
+ # GH 12163
500
+ expected = pd.Series(dtype=object), MyTz()
501
+ result = tm.round_trip_pickle(expected)
502
503
+ tm.assert_series_equal(result[0], expected[0])
504
+ assert isinstance(result[1], MyTz)
pandas/tests/series/test_constructors.py
@@ -1115,6 +1115,15 @@ def create_data(constructor):
1115
tm.assert_series_equal(result_datetime, expected)
1116
tm.assert_series_equal(result_Timestamp, expected)
1117
1118
+ def test_contructor_dict_tuple_indexer(self):
1119
+ # GH 12948
1120
+ data = {(1, 1, None): -1.0}
1121
+ result = Series(data)
1122
1123
+ -1.0, index=MultiIndex(levels=[[1], [1], [np.nan]], codes=[[0], [0], [-1]])
1124
1125
1126
1127
def test_constructor_mapping(self, non_mapping_dict_subclass):
1128
# GH 29788
1129
ndm = non_mapping_dict_subclass({3: "three"})
pandas/tests/test_multilevel.py
@@ -2147,6 +2147,40 @@ def test_sort_index_level_mixed(self):
2147
sorted_after.drop([("foo", "three")], axis=1),
2148
2149
2150
+ def test_sort_index_categorical_multiindex(self):
2151
+ # GH 15058
2152
+ df = DataFrame(
2153
+ {
2154
+ "a": range(6),
2155
+ "l1": pd.Categorical(
2156
+ ["a", "a", "b", "b", "c", "c"],
2157
+ categories=["c", "a", "b"],
2158
+ ordered=True,
2159
2160
+ "l2": [0, 1, 0, 1, 0, 1],
2161
+ }
2162
2163
+ result = df.set_index(["l1", "l2"]).sort_index()
2164
+ expected = DataFrame(
2165
+ [4, 5, 0, 1, 2, 3],
2166
+ columns=["a"],
2167
+ index=MultiIndex(
2168
+ levels=[
2169
+ pd.CategoricalIndex(
2170
+ ["c", "a", "b"],
2171
2172
2173
+ name="l1",
2174
+ dtype="category",
2175
2176
+ [0, 1],
2177
2178
+ codes=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
2179
+ names=["l1", "l2"],
2180
2181
2182
2183
2184
def test_is_lexsorted(self):
2185
levels = [[0, 1], [0, 1, 2]]
2186
0 commit comments