[ 
https://issues.apache.org/jira/browse/ARROW-10505?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17231560#comment-17231560
 ] 

Joris Van den Bossche commented on ARROW-10505:
-----------------------------------------------

Before doing a lot of custom workarounds here, we should maybe also report it 
to cython to see if it is solvable on their end (I was planning to do this when 
that issue came up in the mentioned patch, but never got to it. I can try to do 
that next week)

> [Python] Improve validation of cython arguments
> -----------------------------------------------
>
>                 Key: ARROW-10505
>                 URL: https://issues.apache.org/jira/browse/ARROW-10505
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Python
>    Affects Versions: 2.0.0
>            Reporter: Ben Kietzman
>            Priority: Major
>
> Typing parameters in cython functions (for example
> {code:java}
> def validate(self, Schema schema not None):
> {code}
> )
>  is intuitive but provides uninformative error messages when the type doesn't 
> match expectations. See {{FileSystemDataset.from_paths}} (ARROW-8290) for an 
> instance of manual validation to make a high traffic function more friendly.
> {code:java}
>         for arg, class_, name in [
>             (schema, Schema, 'schema'),
>             (format, FileFormat, 'format'),
>             (filesystem, FileSystem, 'filesystem'),
>             (root_partition, Expression, 'root_partition')
>         ]:
>             if not isinstance(arg, class_):
>                 raise TypeError(
>                     "Argument '{0}' has incorrect type (expected {1}, "
>                     "got {2})".format(name, class_.__name__, type(arg))
>                 )
> {code}
> It seems we could do better by applying a validating decorator:
> {code:python}
> @param_types(schema=Schema, format=Format, filesystem=FileSystem,
>              root_partition=(None,Expression))
> def from_paths(paths, schema, format,
>                filesystem, partitions, root_partition):
> {code}
> This seems compact enough to add to any or all {{def functions}}, improving 
> error messages and hiding validation boilerplate.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to