Skip to content

Commit 677932f

Browse files
authored
Merge pull request #24 from openscm/more-accessors
More accessors
2 parents d869581 + e84d1b0 commit 677932f

28 files changed

+1157
-309
lines changed

changelog/24.breaking.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Renamed pandas_openscm.register_pandas_accessor to [pandas_openscm.register_pandas_accessors][] (with a trailing 's') as accessors are now also registered for [pandas Series][pandas.Series]
2+
- Renamed pandas_openscm.accessors.DataFramePandasOpenSCMAccessor to [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor][]
3+
- Renamed `df_unit_level` to `unit_level` in [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.convert_unit_like][]
4+
- Renamed `df` to `pobj` in [pandas_openscm.index_manipulation.set_index_levels_func][], [pandas_openscm.unit_conversion.convert_unit_from_target_series][], [pandas_openscm.unit_conversion.convert_unit][] and [pandas_openscm.unit_conversion.convert_unit_like][]

changelog/24.feature.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added some accessors for [pandas Series][pandas.Series] via [pandas_openscm.accessors.PandasSeriesOpenSCMAccessor][]. Note that this is not feature complete yet, tracking in [#25](https://github.com/openscm/pandas-openscm/issues/25)

changelog/24.improvement.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[pandas_openscm.index_manipulation.set_index_levels_func][], [pandas_openscm.unit_conversion.convert_unit_from_target_series][], [pandas_openscm.unit_conversion.convert_unit][] and [pandas_openscm.unit_conversion.convert_unit_like][] now explicitly support [pd.Series][pandas.Series]

changelog/24.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added [pandas_openscm.testing.convert_to_desired_type] and [pandas_openscm.testing.check_result] to help with testing support for [pd.DataFrame][pandas.DataFrame] and [pd.Series][pandas.Series]

docs/changelog.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ from the examples given in that link.
2525

2626
### 🆕 Features
2727

28-
- - Added unit conversion APIs: [pandas_openscm.unit_conversion.convert_unit] and [pandas_openscm.unit_conversion.convert_unit_like] and the corresponding accessors [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.convert_unit] and [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.convert_unit_like]
29-
- Added the helper: [pandas_openscm.index_manipulation.ensure_is_multiindex] and the corresponding accessors [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.ensure_index_is_multiindex] and [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.eiim]
28+
- - Added unit conversion APIs: [pandas_openscm.unit_conversion.convert_unit] and [pandas_openscm.unit_conversion.convert_unit_like] and the corresponding accessors [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.convert_unit] and [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.convert_unit_like]
29+
- Added the helper: [pandas_openscm.index_manipulation.ensure_is_multiindex] and the corresponding accessors [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.ensure_index_is_multiindex] and [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.eiim]
3030

3131
([#23](https://github.com/openscm/pandas-openscm/pull/23))
3232

@@ -46,7 +46,7 @@ from the examples given in that link.
4646

4747
### 🆕 Features
4848

49-
- Added [pandas_openscm.index_manipulation.set_levels][] and the corresponding accessor [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.set_index_levels][] ([#18](https://github.com/openscm/pandas-openscm/pull/18))
49+
- Added [pandas_openscm.index_manipulation.set_levels][] and the corresponding accessor [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.set_index_levels][] ([#18](https://github.com/openscm/pandas-openscm/pull/18))
5050

5151

5252
## Pandas-OpenSCM v0.5.0 (2025-05-10)
@@ -84,7 +84,7 @@ from the examples given in that link.
8484
### 🆕 Features
8585

8686
- Add compare_close function to compare two dataframes. ([#16](https://github.com/openscm/pandas-openscm/pull/16))
87-
- Added [pandas_openscm.index_manipulation.update_levels_from_other][] and the corresponding accessor [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.update_index_levels_from_other][] ([#17](https://github.com/openscm/pandas-openscm/pull/17))
87+
- Added [pandas_openscm.index_manipulation.update_levels_from_other][] and the corresponding accessor [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.update_index_levels_from_other][] ([#17](https://github.com/openscm/pandas-openscm/pull/17))
8888

8989

9090
## Pandas-OpenSCM v0.4.1 (2025-04-12)
@@ -93,21 +93,21 @@ from the examples given in that link.
9393

9494
- Fixed up [pandas_openscm.index_manipulation.update_levels][].
9595
It now drops unused levels by default first, to avoid applying the updates to values that aren't being used.
96-
The same fixes are propagated to [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.update_index_levels][] and [pandas_openscm.index_manipulation.update_index_levels_func][]. ([#14](https://github.com/openscm/pandas-openscm/pull/14))
96+
The same fixes are propagated to [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.update_index_levels][] and [pandas_openscm.index_manipulation.update_index_levels_func][]. ([#14](https://github.com/openscm/pandas-openscm/pull/14))
9797

9898

9999
## Pandas-OpenSCM v0.4.0 (2025-04-11)
100100

101101
### 🆕 Features
102102

103-
- Added [pandas_openscm.index_manipulation.update_levels][] and the corresponding accessor [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.update_index_levels][] ([#13](https://github.com/openscm/pandas-openscm/pull/13))
103+
- Added [pandas_openscm.index_manipulation.update_levels][] and the corresponding accessor [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.update_index_levels][] ([#13](https://github.com/openscm/pandas-openscm/pull/13))
104104

105105

106106
## Pandas-OpenSCM v0.3.3 (2025-03-30)
107107

108108
### 🆕 Features
109109

110-
- - Added a method for converting to long data, see [pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.to_long_data][pandas_openscm.accessors.DataFramePandasOpenSCMAccessor.to_long_data] ([#12](https://github.com/openscm/pandas-openscm/pull/12))
110+
- - Added a method for converting to long data, see [pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.to_long_data][pandas_openscm.accessors.PandasDataFrameOpenSCMAccessor.to_long_data] ([#12](https://github.com/openscm/pandas-openscm/pull/12))
111111

112112

113113
## Pandas-OpenSCM v0.3.2 (2025-03-27)

docs/further-background/openscmdb-backend-speed/openscmdb-backend-speed-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
if GIT_REPO.is_dirty():
3737
COMMIT = f"{COMMIT}-dirty"
3838

39-
pandas_openscm.register_pandas_accessor()
39+
pandas_openscm.register_pandas_accessors()
4040

4141

4242
@define

docs/how-to-guides/how-to-make-a-plume-plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import numpy as np
3030
import openscm_units
3131

32-
from pandas_openscm import register_pandas_accessor
32+
from pandas_openscm import register_pandas_accessors
3333
from pandas_openscm.plotting import PlumePlotter
3434
from pandas_openscm.testing import create_test_df
3535

@@ -40,7 +40,7 @@
4040
# Register the openscm accessor for pandas objects
4141
# (we don't do this on import
4242
# as we have had bad experiences with implicit behaviour like that)
43-
register_pandas_accessor()
43+
register_pandas_accessors()
4444

4545
# %% [markdown]
4646
# ## Basics

docs/pandas-accessors.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,43 @@ The accessors must be registered before they can be used
88
(we do this to avoid imports of any of our modules having side effects,
99
which is a pattern we have had bad experiences with in the past).
1010
This is done with
11-
[register_pandas_accessor][pandas_openscm.accessors.register_pandas_accessor],
11+
[register_pandas_accessors][pandas_openscm.accessors.register_pandas_accessors],
1212

1313
By default, the accessors are provided under the "openscm" namespace
1414
and this is how the accessors are documented below.
1515
However, the namespace can be customised when using
16-
[register_pandas_accessor][pandas_openscm.accessors.register_pandas_accessor],
16+
[register_pandas_accessors][pandas_openscm.accessors.register_pandas_accessors],
1717
should you wish to use a different namespace for the accessor.
1818

1919
For the avoidance of doubt, in order to register/activate the accessors,
2020
you will need to run something like:
2121

2222
```python
23-
from pandas_openscm.accessors import register_pandas_accessor
23+
from pandas_openscm.accessors import register_pandas_accessors
2424

25-
# The 'pd.DataFrame.openscm' namespace will not be available at this point.
25+
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespace
26+
# will not be available at this point.
2627

2728
# Register the accessors
28-
register_pandas_accessor()
29+
register_pandas_accessors()
2930

30-
# The 'pd.DataFrame.openscm' namespace
31+
# The 'pd.DataFrame.openscm' and 'pd.Series.openscm' namespace
3132
# (or whatever other custom namespace you chose to register)
3233
# will now be available.
3334
```
3435

3536
The full accessor API is documented below.
3637

37-
::: pandas_openscm.accessors.DataFramePandasOpenSCMAccessor
38+
::: pandas_openscm.accessors.dataframe.PandasDataFrameOpenSCMAccessor
3839
handler: python_accessors
3940
options:
4041
namespace: "pd.DataFrame.openscm"
4142
show_root_full_path: false
4243
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

docs/tutorials/unit-conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import pandas_indexing as pix
3030
import pint
3131

32-
from pandas_openscm import register_pandas_accessor
32+
from pandas_openscm import register_pandas_accessors
3333
from pandas_openscm.testing import create_test_df
3434
from pandas_openscm.unit_conversion import (
3535
AmbiguousTargetUnitError,
@@ -45,7 +45,7 @@
4545
# Register the openscm accessor for pandas objects
4646
# (we don't do this on import
4747
# as we have had bad experiences with implicit behaviour like that)
48-
register_pandas_accessor()
48+
register_pandas_accessors()
4949

5050
# %% [markdown]
5151
# ## Basics

src/pandas_openscm/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
import importlib.metadata
66

7-
from pandas_openscm.accessors import register_pandas_accessor
7+
from pandas_openscm.accessors import register_pandas_accessors
88

99
__version__ = importlib.metadata.version("pandas_openscm")
1010

11-
__all__ = ["register_pandas_accessor"]
11+
__all__ = ["register_pandas_accessors"]

0 commit comments

Comments
 (0)