Skip to content

Commit 26d6b65

Browse files
committed
use python's naming convention for classes
1 parent 9fb429c commit 26d6b65

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

janitor/utils.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ def _computations_pivot_wider(
17961796
return df
17971797

17981798

1799-
class CATEGORY_ORDER(Enum):
1799+
class CategoryOrder(Enum):
18001800
"""
18011801
order types for encode_categorical.
18021802
"""
@@ -1931,7 +1931,7 @@ def as_categorical_checks(df: pd.DataFrame, **kwargs) -> dict:
19311931
if order is not None:
19321932
check("order", order, [str])
19331933

1934-
category_order_types = [ent.value for ent in CATEGORY_ORDER]
1934+
category_order_types = [ent.value for ent in CategoryOrder]
19351935
if order.lower() not in category_order_types:
19361936
raise ValueError(
19371937
"""
@@ -1973,13 +1973,13 @@ def _computations_as_categorical(df: pd.DataFrame, **kwargs) -> pd.DataFrame:
19731973
if (cat is None) and (order is None):
19741974
cat_dtype = pd.CategoricalDtype()
19751975

1976-
elif (cat is None) and (order is CATEGORY_ORDER.SORT.value):
1976+
elif (cat is None) and (order is CategoryOrder.SORT.value):
19771977
cat = df[column_name].factorize(sort=True)[-1]
19781978
if cat.empty:
19791979
raise ValueError(error_msg)
19801980
cat_dtype = pd.CategoricalDtype(categories=cat, ordered=True)
19811981

1982-
elif (cat is None) and (order is CATEGORY_ORDER.APPEARANCE.value):
1982+
elif (cat is None) and (order is CategoryOrder.APPEARANCE.value):
19831983
cat = df[column_name].factorize(sort=False)[-1]
19841984
if cat.empty:
19851985
raise ValueError(error_msg)
@@ -2265,7 +2265,7 @@ def _column_sel_dispatch(columns_to_select, df): # noqa: F811
22652265
return filtered_columns
22662266

22672267

2268-
class JOINOPERATOR(Enum):
2268+
class JoinOperator(Enum):
22692269
"""
22702270
List of operators used in conditional_join.
22712271
"""
@@ -2278,7 +2278,7 @@ class JOINOPERATOR(Enum):
22782278
NOT_EQUAL = "!="
22792279

22802280

2281-
class JOINTYPES(Enum):
2281+
class JoinTypes(Enum):
22822282
"""
22832283
List of join types for conditional_join.
22842284
"""
@@ -2295,7 +2295,7 @@ def _check_operator(op: str):
22952295
22962296
Used in `conditional_join`.
22972297
"""
2298-
sequence_of_operators = {op.value for op in JOINOPERATOR}
2298+
sequence_of_operators = {op.value for op in JoinOperator}
22992299
if op not in sequence_of_operators:
23002300
raise ValueError(
23012301
f"""
@@ -2399,7 +2399,7 @@ def _conditional_join_preliminary_checks(
23992399

24002400
check("how", how, [str])
24012401

2402-
join_types = {jointype.value for jointype in JOINTYPES}
2402+
join_types = {jointype.value for jointype in JoinTypes}
24032403
if how not in join_types:
24042404
raise ValueError(f"`how` should be one of {', '.join(join_types)}.")
24052405

@@ -2451,7 +2451,7 @@ def _conditional_join_type_check(
24512451

24522452
if (
24532453
is_categorical_dtype(left_column)
2454-
and op != JOINOPERATOR.STRICTLY_EQUAL.value
2454+
and op != JoinOperator.STRICTLY_EQUAL.value
24552455
):
24562456
raise ValueError(
24572457
"""
@@ -2462,7 +2462,7 @@ def _conditional_join_type_check(
24622462

24632463
if (
24642464
is_string_dtype(left_column)
2465-
and op != JOINOPERATOR.STRICTLY_EQUAL.value
2465+
and op != JoinOperator.STRICTLY_EQUAL.value
24662466
):
24672467
raise ValueError(
24682468
"""
@@ -2767,14 +2767,14 @@ def _create_conditional_join_empty_frame(
27672767
df.columns = pd.MultiIndex.from_product([["left"], df.columns])
27682768
right.columns = pd.MultiIndex.from_product([["right"], right.columns])
27692769

2770-
if how == JOINTYPES.INNER.value:
2770+
if how == JoinTypes.INNER.value:
27712771
df = df.dtypes.to_dict()
27722772
right = right.dtypes.to_dict()
27732773
df = {**df, **right}
27742774
df = {key: pd.Series([], dtype=value) for key, value in df.items()}
27752775
return pd.DataFrame(df)
27762776

2777-
if how == JOINTYPES.LEFT.value:
2777+
if how == JoinTypes.LEFT.value:
27782778
right = right.dtypes.to_dict()
27792779
right = {
27802780
key: float if dtype.kind == "i" else dtype
@@ -2786,7 +2786,7 @@ def _create_conditional_join_empty_frame(
27862786
right = pd.DataFrame(right)
27872787
return df.join(right, how=how, sort=False)
27882788

2789-
if how == JOINTYPES.RIGHT.value:
2789+
if how == JoinTypes.RIGHT.value:
27902790
df = df.dtypes.to_dict()
27912791
df = {
27922792
key: float if dtype.kind == "i" else dtype
@@ -2817,31 +2817,31 @@ def _create_conditional_join_frame(
28172817
df.columns = pd.MultiIndex.from_product([["left"], df.columns])
28182818
right.columns = pd.MultiIndex.from_product([["right"], right.columns])
28192819

2820-
if how == JOINTYPES.INNER.value:
2820+
if how == JoinTypes.INNER.value:
28212821
df = df.loc[left_index]
28222822
right = right.loc[right_index]
28232823
df.index = pd.RangeIndex(start=0, stop=left_index.size)
28242824
right.index = df.index
28252825
return pd.concat([df, right], axis="columns", join=how, sort=False)
28262826

2827-
if how == JOINTYPES.LEFT.value:
2827+
if how == JoinTypes.LEFT.value:
28282828
right = right.loc[right_index]
28292829
right.index = left_index
28302830
return df.join(right, how=how, sort=False).reset_index(drop=True)
28312831

2832-
if how == JOINTYPES.RIGHT.value:
2832+
if how == JoinTypes.RIGHT.value:
28332833
df = df.loc[left_index]
28342834
df.index = right_index
28352835
return df.join(right, how=how, sort=False).reset_index(drop=True)
28362836

28372837

28382838
less_than_join_types = {
2839-
JOINOPERATOR.LESS_THAN.value,
2840-
JOINOPERATOR.LESS_THAN_OR_EQUAL.value,
2839+
JoinOperator.LESS_THAN.value,
2840+
JoinOperator.LESS_THAN_OR_EQUAL.value,
28412841
}
28422842
greater_than_join_types = {
2843-
JOINOPERATOR.GREATER_THAN.value,
2844-
JOINOPERATOR.GREATER_THAN_OR_EQUAL.value,
2843+
JoinOperator.GREATER_THAN.value,
2844+
JoinOperator.GREATER_THAN_OR_EQUAL.value,
28452845
}
28462846

28472847

@@ -2856,17 +2856,17 @@ def _generic_func_cond_join(
28562856
strict = False
28572857

28582858
if op in {
2859-
JOINOPERATOR.GREATER_THAN.value,
2860-
JOINOPERATOR.LESS_THAN.value,
2861-
JOINOPERATOR.NOT_EQUAL.value,
2859+
JoinOperator.GREATER_THAN.value,
2860+
JoinOperator.LESS_THAN.value,
2861+
JoinOperator.NOT_EQUAL.value,
28622862
}:
28632863
strict = True
28642864

28652865
if op in less_than_join_types:
28662866
return _less_than_indices(left_c, right_c, strict, len_conditions)
28672867
elif op in greater_than_join_types:
28682868
return _greater_than_indices(left_c, right_c, strict, len_conditions)
2869-
elif op == JOINOPERATOR.NOT_EQUAL.value:
2869+
elif op == JoinOperator.NOT_EQUAL.value:
28702870
return _not_equal_indices(left_c, right_c)
28712871
else:
28722872
return _equal_indices(left_c, right_c, len_conditions)
@@ -2906,7 +2906,7 @@ def _conditional_join_compute(
29062906

29072907
_conditional_join_type_check(left_c, right_c, op)
29082908

2909-
if op == JOINOPERATOR.STRICTLY_EQUAL.value:
2909+
if op == JoinOperator.STRICTLY_EQUAL.value:
29102910
eq_check = True
29112911
elif op in less_greater_types:
29122912
less_great = True
@@ -2955,12 +2955,12 @@ def _conditional_join_compute(
29552955

29562956

29572957
operator_map = {
2958-
JOINOPERATOR.STRICTLY_EQUAL.value: operator.eq,
2959-
JOINOPERATOR.LESS_THAN.value: operator.lt,
2960-
JOINOPERATOR.LESS_THAN_OR_EQUAL.value: operator.le,
2961-
JOINOPERATOR.GREATER_THAN.value: operator.gt,
2962-
JOINOPERATOR.GREATER_THAN_OR_EQUAL.value: operator.ge,
2963-
JOINOPERATOR.NOT_EQUAL.value: operator.ne,
2958+
JoinOperator.STRICTLY_EQUAL.value: operator.eq,
2959+
JoinOperator.LESS_THAN.value: operator.lt,
2960+
JoinOperator.LESS_THAN_OR_EQUAL.value: operator.le,
2961+
JoinOperator.GREATER_THAN.value: operator.gt,
2962+
JoinOperator.GREATER_THAN_OR_EQUAL.value: operator.ge,
2963+
JoinOperator.NOT_EQUAL.value: operator.ne,
29642964
}
29652965

29662966

@@ -2977,12 +2977,12 @@ def _multiple_conditional_join_eq(
29772977
eq_cond = [
29782978
cond
29792979
for cond in conditions
2980-
if cond[-1] == JOINOPERATOR.STRICTLY_EQUAL.value
2980+
if cond[-1] == JoinOperator.STRICTLY_EQUAL.value
29812981
]
29822982
rest = [
29832983
cond
29842984
for cond in conditions
2985-
if cond[-1] != JOINOPERATOR.STRICTLY_EQUAL.value
2985+
if cond[-1] != JoinOperator.STRICTLY_EQUAL.value
29862986
]
29872987

29882988
# get rid of nulls, if any
@@ -3015,7 +3015,7 @@ def _multiple_conditional_join_eq(
30153015
# get join indices
30163016
# these are positional, not label indices
30173017
result = _generic_func_cond_join(
3018-
left_c, right_c, JOINOPERATOR.STRICTLY_EQUAL.value, 2
3018+
left_c, right_c, JoinOperator.STRICTLY_EQUAL.value, 2
30193019
)
30203020

30213021
if result is None:
@@ -3109,7 +3109,7 @@ def _multiple_conditional_join_le_lt(
31093109
lt_gt = left_on, right_on, op
31103110
# no point checking for `!=`, since best case scenario
31113111
# they'll have the same no of rows for the less/greater operators
3112-
elif op == JOINOPERATOR.NOT_EQUAL.value:
3112+
elif op == JoinOperator.NOT_EQUAL.value:
31133113
continue
31143114

31153115
left_c = df.loc[df_index, left_on]

0 commit comments

Comments
 (0)