From d82dd8a757d5d837c9c9b79d3c89347b66111aab Mon Sep 17 00:00:00 2001 From: Kaustbh Date: Fri, 18 Apr 2025 09:40:47 +0530 Subject: [PATCH 1/5] Correct broken source links for `set_params` and `get_params` in Aeon estimator docs --- aeon/base/_base.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 5a336c7397..2176e54262 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -219,6 +219,23 @@ def get_class_tag( return tag_value + def get_params(self, deep=True): + """ + Get parameters for this estimator. + + Parameters + ---------- + deep : bool, default=True + If True, will return the parameters for this estimator and + contained subobjects that are estimators. + + Returns + ------- + params : dict + Parameter names mapped to their values. + """ + return super().get_params(deep=deep) + def get_tags(self): """ Get tags from estimator. @@ -280,6 +297,26 @@ def get_tag(self, tag_name, raise_error=True, tag_value_default=None): return tag_value + def set_params(self, **params): + """Set the parameters of this estimator. + + The method works on simple estimators as well as on nested objects + (such as :class:`~sklearn.pipeline.Pipeline`). The latter have + parameters of the form ``__`` so that it's + possible to update each component of a nested object. + + Parameters + ---------- + **params : dict + Estimator parameters. + + Returns + ------- + self : estimator instance + Estimator instance. + """ + super().set_params(**params) + def set_tags(self, **tag_dict): """ Set dynamic tags to given values. From 2460201d07348cfaec9a459220b76676ddf657a0 Mon Sep 17 00:00:00 2001 From: Kaustbh Date: Thu, 24 Apr 2025 13:34:25 +0530 Subject: [PATCH 2/5] made necessary changes --- aeon/base/_base.py | 37 ------------------------------------- docs/conf.py | 4 ++++ 2 files changed, 4 insertions(+), 37 deletions(-) diff --git a/aeon/base/_base.py b/aeon/base/_base.py index 2176e54262..5a336c7397 100644 --- a/aeon/base/_base.py +++ b/aeon/base/_base.py @@ -219,23 +219,6 @@ def get_class_tag( return tag_value - def get_params(self, deep=True): - """ - Get parameters for this estimator. - - Parameters - ---------- - deep : bool, default=True - If True, will return the parameters for this estimator and - contained subobjects that are estimators. - - Returns - ------- - params : dict - Parameter names mapped to their values. - """ - return super().get_params(deep=deep) - def get_tags(self): """ Get tags from estimator. @@ -297,26 +280,6 @@ def get_tag(self, tag_name, raise_error=True, tag_value_default=None): return tag_value - def set_params(self, **params): - """Set the parameters of this estimator. - - The method works on simple estimators as well as on nested objects - (such as :class:`~sklearn.pipeline.Pipeline`). The latter have - parameters of the form ``__`` so that it's - possible to update each component of a nested object. - - Parameters - ---------- - **params : dict - Estimator parameters. - - Returns - ------- - self : estimator instance - Estimator instance. - """ - super().set_params(**params) - def set_tags(self, **tag_dict): """ Set dynamic tags to given values. diff --git a/docs/conf.py b/docs/conf.py index 65844dbb71..54034bc2e6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -183,6 +183,10 @@ def find_source(): filename = "aeon/%s#L%d-L%d" % find_source() except Exception: filename = info["module"].replace(".", "/") + ".py" + + if filename.split("/")[0] == "aeon": + return None + return "https://github.com/aeon-toolkit/aeon/blob/{}/{}".format( github_tag, filename, From 769850e7ca771f48cd3ec62327eed223b65ea3d3 Mon Sep 17 00:00:00 2001 From: Kaustbh Date: Thu, 24 Apr 2025 13:35:31 +0530 Subject: [PATCH 3/5] made necessary changes --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 54034bc2e6..c8c26a5e5a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -184,7 +184,7 @@ def find_source(): except Exception: filename = info["module"].replace(".", "/") + ".py" - if filename.split("/")[0] == "aeon": + if filename.split("/")[0] != "aeon": return None return "https://github.com/aeon-toolkit/aeon/blob/{}/{}".format( From 2fb0b7ba300ab76143fc15e5a8f4dbfe3378bc03 Mon Sep 17 00:00:00 2001 From: Kaustbh Date: Mon, 26 May 2025 21:53:39 +0530 Subject: [PATCH 4/5] modified linkcode_resolve --- docs/conf.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index bf5e5beed3..4a1ebfdfcd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -166,29 +166,46 @@ def linkcode_resolve(domain, info): def find_source(): # try to find the file and line number, based on code from numpy: # https://github.com/numpy/numpy/blob/main/doc/source/conf.py#L286 + + import inspect + import os + obj = sys.modules[info["module"]] for part in info["fullname"].split("."): obj = getattr(obj, part) - import inspect - import os - obj = inspect.unwrap(obj) + if inspect.isfunction(obj): + obj = inspect.unwrap(obj) + + try: + fn = inspect.getsourcefile(obj) + except TypeError: + fn = None + + if not fn: + return None + + startdir = Path(aeon.__file__).parent.parent + try: + fn = os.path.relpath(fn, start=startdir).replace(os.path.sep, "/") + except ValueError: + return None + + if not fn.startswith("aeon/"): + return None - fn = inspect.getsourcefile(obj) - fn = os.path.relpath(fn, start=os.path.dirname(aeon.__file__)) source, lineno = inspect.getsourcelines(obj) return fn, lineno, lineno + len(source) - 1 if domain != "py" or not info["module"]: return None try: - filename = "aeon/%s#L%d-L%d" % find_source() + result = find_source() + if not result: + return None + filename = "%s#L%d-L%d" % result except Exception: filename = info["module"].replace(".", "/") + ".py" - - if filename.split("/")[0] != "aeon": - return None - return "https://github.com/aeon-toolkit/aeon/blob/{}/{}".format( github_tag, filename, From f7b2b2e2003c7090879c171e4552da4124bdc524 Mon Sep 17 00:00:00 2001 From: Kaustbh Date: Tue, 27 May 2025 22:45:46 +0530 Subject: [PATCH 5/5] added comments --- docs/conf.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 4a1ebfdfcd..5948fc49e5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -170,30 +170,41 @@ def find_source(): import inspect import os + # Get the top-level object from the module name obj = sys.modules[info["module"]] + + # Traverse dotted path (e.g., module.submodule.Class.method) for part in info["fullname"].split("."): obj = getattr(obj, part) + # Unwrapping decorators (if any), so we can get the true + # source function if inspect.isfunction(obj): obj = inspect.unwrap(obj) + # Get the source filename try: fn = inspect.getsourcefile(obj) except TypeError: fn = None + # If no source file is found, return None (no link) if not fn: return None + # Make filename relative to the aeon source directory startdir = Path(aeon.__file__).parent.parent try: fn = os.path.relpath(fn, start=startdir).replace(os.path.sep, "/") except ValueError: return None + # Filter out files not in the aeon package + # (e.g., inherited from sklearn) if not fn.startswith("aeon/"): return None + # Get line range of the object source, lineno = inspect.getsourcelines(obj) return fn, lineno, lineno + len(source) - 1