Skip to content

Commit 242219f

Browse files
authored
Change hasattr to callable (has2k1#421)
1 parent 5359fb6 commit 242219f

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ examples/.ipynb_checkpoints
5555
*.mo
5656
*.pot
5757

58-
# Django stuff:
58+
# Django stuff
5959
*.log
6060

6161
# Sphinx documentation
@@ -65,3 +65,7 @@ doc/generated/
6565
# PyBuilder
6666
target/
6767

68+
# OS generated files
69+
.DS_Store
70+
.DS_Store?
71+

plotnine/layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def generate_data(self, plot_data):
249249
"{} layer expects a dataframe, but it got "
250250
"{} instead.".format(_geom_name, _data_name)
251251
)
252-
elif hasattr(self.data, '__call__'):
252+
elif callable(self.data):
253253
self.data = self.data(plot_data)
254254
if not isinstance(self.data, pd.DataFrame):
255255
raise PlotnineError(

plotnine/stats/smoothers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def predictdf(data, xseq, **params):
3737
msg = "Method should be one of {}"
3838
raise PlotnineError(msg.format(list(methods.keys())))
3939

40-
if not hasattr(method, '__call__'):
40+
if not callable(method):
4141
msg = ("'method' should either be a string or a function"
4242
"with the signature `func(data, xseq, **params)`")
4343
raise PlotnineError()

plotnine/stats/stat_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def compute_group(cls, data, scales, **params):
6262
raise PlotnineError(
6363
"Missing 'x' aesthetic and 'xlim' is {}".format(xlim))
6464

65-
if not hasattr(fun, '__call__'):
65+
if not callable(fun):
6666
raise PlotnineError(
6767
"stat_function requires parameter 'fun' to be " +
6868
"a function or any other callable object")

0 commit comments

Comments
 (0)