Skip to content

Commit 343a2bb

Browse files
committed
Pre-commit hook fixes.
1 parent 80e07ea commit 343a2bb

File tree

2 files changed

+56
-37
lines changed

2 files changed

+56
-37
lines changed

pandas_flavor/register.py

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,37 @@
44
register_dataframe_accessor,
55
)
66
import inspect
7-
from contextlib import nullcontext
87

98
method_call_ctx_factory = None
109

1110

1211
def handle_pandas_extension_call(method, method_signature, obj, args, kwargs):
13-
"""
14-
This function is called when the user calls a pandas DataFrame object's method.
15-
The pandas extension mechanism passes args and kwargs of original method call as it is applied to obj
12+
"""Handle pandas extension call.
13+
14+
This function is called when the user calls
15+
a pandas DataFrame object's method.
16+
The pandas extension mechanism passes args and kwargs
17+
of the original method call as it is applied to obj.
1618
1719
Our implementation uses the global variable `method_call_ctx_factory`.
1820
1921
`method_call_ctx_factory` can be either None or an abstract class.
2022
21-
When `method_call_ctx_factory` is None, the implementation calls the registered method with unmodified args and kwargs and returns underlying method result.
22-
23-
When `method_call_ctx_factory` is not None, `method_call_ctx_factory` is expected to refer to the function to create the context object.
24-
The context object will be used to process inputs and outputs of `method` calls.
25-
It is also possible that the context object method `handle_start_method_call`
23+
When `method_call_ctx_factory` is None,
24+
the implementation calls the registered method
25+
with unmodified args and kwargs and returns underlying method result.
26+
27+
When `method_call_ctx_factory` is not None,
28+
`method_call_ctx_factory` is expected to refer to
29+
the function to create the context object.
30+
The context object will be used to process
31+
inputs and outputs of `method` calls.
32+
It is also possible that
33+
the context object method `handle_start_method_call`
2634
will modify original args and kwargs before `method` call.
2735
28-
`method_call_ctx_factory` is a function that should have the following signature:
36+
`method_call_ctx_factory` is a function
37+
that should have the following signature:
2938
3039
`f(method_name: str, args: list, kwargs: dict) -> MethodCallCtx`
3140
@@ -50,24 +59,17 @@ def handle_end_method_call(self, ret: object) -> None:
5059
raise NotImplemented
5160
5261
53-
Parameters
54-
----------
55-
method :
56-
method object as registered by decorator register_dataframe_method (or register_series_method)
57-
method_signature :
58-
signature of method as returned by inspect.signature
59-
obj :
60-
pandas object - Dataframe or Series
61-
*args : list
62-
The arguments to pass to the registered method.
63-
**kwargs : dict
64-
The keyword arguments to pass to the registered method.
65-
66-
Returns
67-
-------
68-
object :
69-
The result of calling of the method.
70-
"""
62+
Args:
63+
method (callable): method object as registered by decorator
64+
register_dataframe_method (or register_series_method)
65+
method_signature: signature of method as returned by inspect.signature
66+
obj: Dataframe or Series
67+
args: The arguments to pass to the registered method.
68+
kwargs: The keyword arguments to pass to the registered method.
69+
70+
Returns:
71+
object`: The result of calling of the method.
72+
""" # noqa: E501
7173

7274
global method_call_ctx_factory
7375
with method_call_ctx_factory(
@@ -93,15 +95,18 @@ def handle_end_method_call(self, ret: object) -> None:
9395
def register_dataframe_method(method):
9496
"""Register a function as a method attached to the Pandas DataFrame.
9597
96-
Example
97-
-------
98-
99-
.. code-block:: python
98+
Example:
10099
101100
@register_dataframe_method
102101
def print_column(df, col):
103102
'''Print the dataframe column given'''
104103
print(df[col])
104+
105+
Args:
106+
method (callable): callable to register as a dataframe method.
107+
108+
Returns:
109+
callable: The original method.
105110
"""
106111

107112
method_signature = inspect.signature(method)
@@ -129,7 +134,14 @@ def __call__(self, *args, **kwargs):
129134

130135

131136
def register_series_method(method):
132-
"""Register a function as a method attached to the Pandas Series."""
137+
"""Register a function as a method attached to the Pandas Series.
138+
139+
Args:
140+
method (callable): callable to register as a series method.
141+
142+
Returns:
143+
callable: The original method.
144+
"""
133145

134146
method_signature = inspect.signature(method)
135147

setup.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
# The rest you shouldn't have to touch too much :)
2525
# ------------------------------------------------
2626
# Except, perhaps the License and Trove Classifiers!
27-
# If you do change the License, remember to change the Trove Classifier for that!
27+
# If you do change the License,
28+
# remember to change the Trove Classifier for that!
2829

2930
here = os.path.abspath(os.path.dirname(__file__))
3031

3132
# Import the README and use it as the long-description.
32-
# Note: this will only work if 'README.rst' is present in your MANIFEST.in file!
33+
# Note: this will only work if 'README.rst'
34+
# is present in your MANIFEST.in file!
3335
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
3436
long_description = "\n" + f.read()
3537

@@ -46,8 +48,13 @@ class UploadCommand(Command):
4648
user_options = []
4749

4850
@staticmethod
49-
def status(s):
50-
"""Prints things in bold."""
51+
def status(s: str):
52+
"""Prints things in bold.
53+
54+
Args:
55+
s: The string to print.
56+
57+
"""
5158
print("\033[1m{0}\033[0m".format(s))
5259

5360
def initialize_options(self):

0 commit comments

Comments
 (0)