Skip to content

Commit 1405667

Browse files
committed
Include test from original issue
Added testcase `test_groupby_sum_with_custom_metadata` for functionality exercised in the #GH-29442. Testcase fails on current code.
1 parent ec7fd00 commit 1405667

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed
+27-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1-
from pandas import DataFrame
1+
import pandas as pd
22

33

4-
class CustomDataFrame(DataFrame):
4+
class SubclassedDataFrame2(pd.DataFrame):
55
"""
66
Extension of DataFrame as described in [guidelines]
77
88
[guidelines]: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#override-constructor-properties # noqa
99
"""
1010

11-
_metadata = ["_custom_metadata"]
11+
# temporary properties
12+
_internal_names = pd.DataFrame._internal_names + ["internal_cache"]
13+
_internal_names_set = set(_internal_names)
14+
15+
# normal properties
16+
_metadata = ["added_property"]
1217

1318
@property
1419
def _constructor(self):
15-
return CustomDataFrame
20+
return SubclassedDataFrame2
1621

1722

1823
def test_groupby_with_custom_metadata():
19-
custom_df = CustomDataFrame(
24+
custom_df = SubclassedDataFrame2(
2025
[[11, 12, 0], [21, 22, 0], [31, 32, 1]], columns=["a", "b", "g"]
2126
)
22-
custom_df._custom_metadata = "Custom metadata"
23-
24-
for _, group_df in custom_df.groupby("g"):
25-
assert group_df._custom_metadata == "Custom metadata"
27+
custom_df.added_property = "hello_pandas"
28+
grouped = custom_df.groupby("g")
29+
for _, group_df in grouped:
30+
assert group_df.added_property == "hello_pandas"
31+
32+
33+
def test_groupby_sum_with_custom_metadata():
34+
my_data_as_dictionary = {
35+
"mycategorical": [1, 1, 2],
36+
"myfloat1": [1.0, 2.0, 3.0],
37+
"myfloat2": [1.0, 2.0, 3.0],
38+
}
39+
sdf = SubclassedDataFrame2(my_data_as_dictionary)
40+
sdf.added_property = "hello pandas"
41+
grouped = sdf.groupby("mycategorical")[["myfloat1", "myfloat2"]]
42+
df = grouped.sum()
43+
assert df.added_property == "hello pandas"

0 commit comments

Comments
 (0)