Skip to content

Commit ce53f4c

Browse files
authored
Merge pull request #30 from openscm/fix-docs
Fix docs build
2 parents ad4630e + 82d4231 commit ce53f4c

13 files changed

+1659
-1274
lines changed

changelog/30.docs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed up the issues related to the docs rendering ([#29](https://github.com/openscm/pandas-openscm/issues/29)) and simplified the documentation of the accessors

changelog/30.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed the dependence on mkdocstrings-python-accessors for building the docs and upgraded to later versions of mkdocs related packages

docs/pandas-accessors.md

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Pandas accessors
22

3-
Pandas-OpenSCM also provides a [pandas][] accessor.
3+
Pandas-OpenSCM also provides [pandas][] accessors.
44
For details of the implementation of this pattern, see
55
[pandas' docs](https://pandas.pydata.org/docs/development/extending.html#registering-custom-accessors).
66

@@ -10,8 +10,7 @@ which is a pattern we have had bad experiences with in the past).
1010
This is done with
1111
[register_pandas_accessors][pandas_openscm.accessors.register_pandas_accessors],
1212

13-
By default, the accessors are provided under the "openscm" namespace
14-
and this is how the accessors are documented below.
13+
By default, the accessors are provided under the "openscm" namespace.
1514
However, the namespace can be customised when using
1615
[register_pandas_accessors][pandas_openscm.accessors.register_pandas_accessors],
1716
should you wish to use a different namespace for the accessor.
@@ -22,29 +21,41 @@ you will need to run something like:
2221
```python
2322
from pandas_openscm.accessors import register_pandas_accessors
2423

25-
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespace
24+
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespaces
2625
# will not be available at this point.
2726

2827
# Register the accessors
2928
register_pandas_accessors()
3029

31-
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespace
32-
# (or whatever other custom namespace you chose to register)
30+
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespaces
3331
# will now be available.
32+
# I.e. you could now do something like
33+
df = pd.DataFrame(
34+
[
35+
[1.1, 0.8, 1.2],
36+
[2.1, np.nan, 8.4],
37+
],
38+
columns=[2010.0, 2015.0, 2025.0],
39+
index=pd.MultiIndex.from_tuples(
40+
[
41+
("sa", "v2", "W"),
42+
("sb", "v2", "W"),
43+
],
44+
names=["scenario", "variable", "unit"],
45+
),
46+
)
47+
48+
# Use pandas-openscm's functionality via the registered accessors.
49+
df.openscm.to_long_data()
50+
51+
# If you want to register the accessors under a custom namespace instead,
52+
# use something like the below instead
53+
register_pandas_accessors(namespace="my_custom_namespace")
54+
55+
# Doing it this way will make the custom namespace available under
56+
# 'pd.DataFrame.my_custom_namespace' and 'pd.Series.my_custom_namespace'.
3457
```
3558

36-
The full accessor API is documented below.
37-
38-
::: pandas_openscm.accessors.dataframe.PandasDataFrameOpenSCMAccessor
39-
handler: python_accessors
40-
options:
41-
namespace: "pd.DataFrame.openscm"
42-
show_root_full_path: false
43-
show_root_heading: true
44-
45-
::: pandas_openscm.accessors.series.PandasSeriesOpenSCMAccessor
46-
handler: python_accessors
47-
options:
48-
namespace: "pd.Series.openscm"
49-
show_root_full_path: false
50-
show_root_heading: true
59+
The full accessor APIs are documented at
60+
[pandas_openscm.accessors.dataframe.PandasDataFrameOpenSCMAccessor][]
61+
and [pandas_openscm.accessors.series.PandasSeriesOpenSCMAccessor][].

mkdocs.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ plugins:
7373
default_handler: python_xref
7474
enable_inventory: true
7575
handlers:
76-
python_xref: &pythonhandleroptions
76+
python_xref:
7777
paths: [src]
78-
import:
78+
inventories:
7979
# Cross-ref helpers (lots included here, remove what you don't want)
8080
- https://www.attrs.org/en/stable/objects.inv
8181
- https://unidata.github.io/cftime/objects.inv
@@ -110,8 +110,21 @@ plugins:
110110
- https://validators.readthedocs.io/en/stable/objects.inv
111111
- http://xarray.pydata.org/en/stable/objects.inv
112112
options:
113+
# It turns out that xref does this check without considering config.
114+
# As a result, every docstring is parsed as a google-style docstring.
115+
# As docstrings are only parsed once, this results in rendering failures.
116+
# Hence, turn off the checks here.
117+
# mkdocs_autorefs catches anything which doesn't end up being a correct reference.
118+
# The fix might be as simple as changing
119+
# `self.collect(ref, PythonOptions())`
120+
# to `self.collect(ref, self.get_options({}))`
121+
# in the python-xref source, but it's hard to predict the side effects
122+
# so we haven't bothered with that route.
123+
check_crossrefs: false
113124
docstring_style: numpy
114-
relative_crossrefs: yes
125+
preload_modules:
126+
- pint
127+
relative_crossrefs: true
115128
separate_signature: true
116129
show_root_heading: false
117130
show_signature_annotations: true
@@ -122,7 +135,6 @@ plugins:
122135
classes: true
123136
functions: true
124137
modules: true
125-
python_accessors: *pythonhandleroptions
126138
# https://squidfunk.github.io/mkdocs-material/plugins/search/
127139
- search
128140
# Add clickable sections to the sidebar

pyproject.toml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,24 @@ dev = [
9494
docs = [
9595
# Key dependencies
9696
# ----------------
97-
"attrs==24.3.0",
98-
"mkdocs-autorefs==1.2.0",
99-
"mkdocs-gen-files==0.5.0",
100-
"mkdocs-literate-nav==0.6.1",
101-
"mkdocs-material==9.5.49",
102-
"mkdocs-section-index==0.3.9",
103-
"mkdocs==1.6.1",
104-
"mkdocstrings-python-accessors>=0.1.1",
105-
"mkdocstrings-python-xref==1.6.2",
106-
"mkdocstrings-python==1.13.0",
107-
"pymdown-extensions==10.13",
108-
"ruff==0.8.6",
97+
"attrs>=24.3.0",
98+
"mkdocs-autorefs>=1.2.0",
99+
"mkdocs-gen-files>=0.5.0",
100+
"mkdocs-literate-nav>=0.6.1",
101+
"mkdocs-material>=9.5.49",
102+
"mkdocs-section-index>=0.3.9",
103+
"mkdocs>=1.6.1",
104+
"mkdocstrings-python-xref>=1.6.2",
105+
"mkdocstrings-python>=1.13.0",
106+
"pymdown-extensions>=10.13",
107+
"ruff>=0.8.6",
109108
# Key dependencies for notebook_based_docs
110109
# ----------------------------------------
111110
"filelock>=3.16.1",
112111
"ipywidgets>=8.1.5",
113-
"jupyterlab==4.3.4",
114-
"jupytext==1.16.6",
115-
"mkdocs-jupyter==0.25.1",
112+
"jupyterlab>=4.3.4",
113+
"jupytext>=1.16.6",
114+
"mkdocs-jupyter>=0.25.1",
116115
"openscm-units>=0.6.3",
117116
"pandas-indexing>=0.6.2",
118117
"pint>=0.24.4",

0 commit comments

Comments
 (0)