Skip to content

Commit fcc8799

Browse files
authored
Merge pull request #9 from kthyng/types
trying type annotations
2 parents 0aa68e6 + f46e147 commit fcc8799

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ repos:
4646
- id: black
4747
language_version: python3
4848

49-
# - repo: https://github.com/pre-commit/mirrors-mypy
50-
# rev: v0.770
51-
# hooks:
52-
# - id: mypy
53-
# exclude: docs/source/conf.py
54-
# args: [--ignore-missing-imports]
49+
- repo: https://github.com/pre-commit/mirrors-mypy
50+
rev: v0.982
51+
hooks:
52+
- id: mypy
53+
additional_dependencies: [types-setuptools]
54+
exclude: docs/source/conf.py
55+
args: [--ignore-missing-imports]
5556

5657
- repo: https://github.com/codespell-project/codespell
5758
rev: v1.16.0

cf_pandas/accessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, pandas_obj):
2121
# if "latitude" not in obj.columns or "longitude" not in obj.columns:
2222
# raise AttributeError("Must have 'latitude' and 'longitude'.")
2323

24-
def __getitem__(self, key):
24+
def __getitem__(self, key: str):
2525
"""Redefinition of dict-like behavior.
2626
This enables user to use syntax `reader[dataset_id]` to read in and
2727
save dataset into the object.

cf_pandas/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _apply_update(self, options_dict):
5555
for k, v in options_dict.items():
5656
if k == "custom_criteria":
5757
options_dict["custom_criteria"] = cfp.always_iterable(
58-
options_dict["custom_criteria"], allowed=(tuple, list)
58+
options_dict["custom_criteria"], allowed=(tuple, list, set)
5959
)
6060
OPTIONS.update(options_dict)
6161

cf_pandas/utils.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,31 @@ def astype(value, type_):
3030
return value
3131

3232

33-
def set_up_criteria(criteria: Optional[dict] = None):
33+
def set_up_criteria(criteria: Union[dict, Iterable] = None) -> ChainMap:
3434
"""Get custom criteria from options.
3535
3636
Parameters
3737
----------
3838
criteria : dict, optional
39-
Criteria to use to map from variable to attributes describing the variable. If user has defined custom_criteria, this will be used by default.
39+
Criteria to use to map from variable to attributes describing the variable. If user has defined
40+
custom_criteria, this will be used by default.
41+
42+
Returns
43+
-------
44+
ChainMap
45+
Criteria
4046
"""
4147

4248
if criteria is None:
4349
if not OPTIONS["custom_criteria"]:
44-
return []
45-
criteria = OPTIONS["custom_criteria"]
46-
47-
if criteria is not None:
48-
criteria = always_iterable(criteria, allowed=(tuple, list, set))
49-
50-
criteria = always_iterable(criteria, allowed=(tuple, list, set))
51-
criteria = ChainMap(*criteria)
52-
53-
return criteria
50+
raise ValueError(
51+
"criteria needs to be defined either using set_options or directly input."
52+
)
53+
criteria_it = OPTIONS["custom_criteria"]
54+
else:
55+
criteria_it = always_iterable(criteria, allowed=(tuple, list, set))
56+
57+
return ChainMap(*criteria_it)
5458

5559

5660
def match_criteria_key(

0 commit comments

Comments
 (0)