Skip to content

Commit d71448b

Browse files
committed
fixed all of the pre-commit style errors for GH issue pandas-dev#58031
1 parent 4f6ee28 commit d71448b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

pandas/core/groupby/ops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,7 @@ def agg_series(
914914
np.ndarray or ExtensionArray
915915
"""
916916

917-
918-
#if objtype is not in np.dtypes, type is preserved but thats bad seems readable
917+
# if objtype is not in np.dtypes, type is preserved
919918
if not isinstance(obj._values, np.ndarray) and obj.dtype != "boolean":
920919
# we can preserve a little bit more aggressively with EA dtype
921920
# because maybe_cast_pointwise_result will do a try/except

pandas/tests/groupby/aggregate/test_other.py

+21-13
Original file line numberDiff line numberDiff line change
@@ -667,19 +667,27 @@ def weird_func(x):
667667
result = df["decimals"].groupby(df["id1"]).agg(weird_func)
668668
tm.assert_series_equal(result, expected, check_names=False)
669669

670+
670671
def test_groupby_agg_boolean_dype():
671672
# GH Issue #58031
672-
# Ensure return type of aggregate dtype has consistent behavior for 'bool' and 'boolean'
673-
# because boolean not covered under numpy
674-
675-
df_boolean = pd.DataFrame({0: [1, 2, 2], 1: [True, True, None]})
676-
df_boolean[1] = df_boolean[1].astype("boolean")
677-
678-
df_bool = pd.DataFrame({0: [1, 2, 2], 1: [True, True, None]})
679-
df_bool[1] = df_bool[1].astype("bool")
680-
681-
boolean_return_type = df_boolean.groupby(by=0).aggregate(lambda s: s.fillna(False).mean()).dtypes.values[0]
682-
bool_return_type = df_bool.groupby(by=0).aggregate(lambda s: s.fillna(False).mean()).dtypes.values[0]
683-
684-
assert boolean_return_type == bool_return_type
673+
# Ensure return type of aggregate dtype has consistent behavior
674+
# for 'bool' and 'boolean' because boolean not covered under numpy
675+
676+
df_boolean = DataFrame({"0": [1, 2, 2], "1": [True, True, None]})
677+
df_boolean[1] = df_boolean["1"].astype("boolean")
678+
679+
df_bool = DataFrame({"0": [1, 2, 2], "1": [True, True, None]})
680+
df_bool[1] = df_bool["1"].astype("bool")
685681

682+
boolean_return_type = (
683+
df_boolean.groupby("0")
684+
.aggregate(lambda s: s.fillna(False).mean())
685+
.dtypes.values[0]
686+
)
687+
bool_return_type = (
688+
df_bool.groupby("0")
689+
.aggregate(lambda s: s.fillna(False).mean())
690+
.dtypes.values[0]
691+
)
692+
693+
assert boolean_return_type == bool_return_type

0 commit comments

Comments
 (0)