You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Ben Kietzman (Jira)" <ji...@apache.org> on 2020/11/05 20:17:00 UTC

[jira] [Created] (ARROW-10505) [Python] Improve validation of cython arguments

Ben Kietzman created ARROW-10505:
------------------------------------

             Summary: [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


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)