Helper function for derived_from to ease testing
(
cls, method, ua_args=None, extra="", skipblocks=0, inconsistencies=None
)
| 894 | |
| 895 | |
| 896 | def _derived_from( |
| 897 | cls, method, ua_args=None, extra="", skipblocks=0, inconsistencies=None |
| 898 | ): |
| 899 | """Helper function for derived_from to ease testing""" |
| 900 | ua_args = ua_args or [] |
| 901 | |
| 902 | # do not use wraps here, as it hides keyword arguments displayed |
| 903 | # in the doc |
| 904 | original_method = getattr(cls, method.__name__) |
| 905 | |
| 906 | doc = getattr(original_method, "__doc__", None) |
| 907 | |
| 908 | if isinstance(original_method, property): |
| 909 | # some things like SeriesGroupBy.unique are generated. |
| 910 | original_method = original_method.fget |
| 911 | if not doc: |
| 912 | doc = getattr(original_method, "__doc__", None) |
| 913 | |
| 914 | if isinstance(original_method, functools.cached_property): |
| 915 | original_method = original_method.func |
| 916 | if not doc: |
| 917 | doc = getattr(original_method, "__doc__", None) |
| 918 | |
| 919 | if doc is None: |
| 920 | doc = "" |
| 921 | |
| 922 | # pandas DataFrame/Series sometimes override methods without setting __doc__ |
| 923 | if not doc and cls.__name__ in {"DataFrame", "Series"}: |
| 924 | for obj in cls.mro(): |
| 925 | obj_method = getattr(obj, method.__name__, None) |
| 926 | if obj_method is not None and obj_method.__doc__: |
| 927 | doc = obj_method.__doc__ |
| 928 | break |
| 929 | |
| 930 | # Insert disclaimer that this is a copied docstring |
| 931 | if doc: |
| 932 | doc = ignore_warning( |
| 933 | doc, |
| 934 | cls, |
| 935 | method.__name__, |
| 936 | extra=extra, |
| 937 | skipblocks=skipblocks, |
| 938 | inconsistencies=inconsistencies, |
| 939 | ) |
| 940 | elif extra: |
| 941 | doc += extra.rstrip("\n") + "\n\n" |
| 942 | |
| 943 | # Mark unsupported arguments |
| 944 | try: |
| 945 | method_args = get_named_args(method) |
| 946 | original_args = get_named_args(original_method) |
| 947 | not_supported = [m for m in original_args if m not in method_args] |
| 948 | except ValueError: |
| 949 | not_supported = [] |
| 950 | if len(ua_args) > 0: |
| 951 | not_supported.extend(ua_args) |
| 952 | if len(not_supported) > 0: |
| 953 | doc = unsupported_arguments(doc, not_supported) |
no test coverage detected
searching dependent graphs…