Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.6.3 #116

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,3 @@ cython_debug/
.issues/
.DS_Store
test.xlsx

16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.7.0 # should match pyproject.toml version
hooks:
- id: black
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: flake8
language_version: python3
- id: ruff

# - repo: https://github.com/numpy/numpydoc
# rev: v1.6.0
# hooks:
# - id: numpydoc-validation
# exclude: (tests|docs|.venv)/.*
20 changes: 20 additions & 0 deletions docs/core/pfline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,25 @@ Another slicing method is implemented with the ``.slice[]`` property. The improv
print(pfl.slice['2024':'2026'])
# --- hide: stop ---

Reindexing
----------

A portfolio line can be reindexed with ``.index()``, using another index, e.g. of another portfolio line. This returns a new portfolio line, with the specified index. Any timestamps that were not present in the original object are filled with "zero" (as applicable).

.. exec_code::

# --- hide: start ---
import portfolyo as pf, pandas as pd
index = pd.date_range('2024', freq='YS', periods=3)
input_df = pd.DataFrame({'w':[200, 220, 300], 'p': [100, 150, 200]}, index)
pfl = pf.PfLine(input_df)
# --- hide: stop ---
# continuation of previous code example
index2 = pd.date_range('2025', freq='YS', periods=3)
pfl.reindex(index2) # 2024 is dropped; 2025 and 2026 are kept; 2027 is new (0)
# --- hide: start ---
print(pfl.reindex(index2))
# --- hide: stop ---


Concatenation
Expand Down Expand Up @@ -390,6 +408,8 @@ General remarks:
# --- hide: start ---
print(repr(pfl_1 == pfl_2 == pfl_3 == pfl_4))

* If two portfolio lines span distinct periods, only their overlap is kept. If instead we want to keep all timestamps, e.g., when adding a portfolio line which spans a quarter to one that spans a year (with the same frequency, e.g. hourly), first use the ``.reindex()`` method on the former with the index of the latter. The values outside the specified quarter are filled with "zero" values as is applicable to the kind of portfolio line under consideration.

* A single value is understood to apply uniformly to each timestamp in the index of the portfolio line.

* When doing arithmatic with a flat portfolio line, the result is again a flat portfolio line.
Expand Down
1,841 changes: 945 additions & 896 deletions poetry.lock

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions portfolyo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Package to analyse and manipulate timeseries related to power and gas offtake portfolios."""

from . import _version, dev, tools
from . import dev, tools
from .core import extendpandas # extend functionalty of pandas
from .core import suppresswarnings
from .core.pfline import Kind, PfLine, Structure, create
Expand All @@ -23,6 +23,9 @@
from .tools.unit import Q_, Unit, ureg
from .tools.wavg import general as wavg

import tomli
from pathlib import Path

VOLUME = Kind.VOLUME
PRICE = Kind.PRICE
REVENUE = Kind.REVENUE
Expand All @@ -31,5 +34,16 @@
extendpandas.apply()
suppresswarnings.apply()

__version__ = _version.get_versions()["version"]

def get_version():
# Find the pyproject.toml file relative to this file
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"

# Open and read the pyproject.toml file using tomli
with pyproject_path.open("rb") as f:
pyproject_data = tomli.load(f)
return pyproject_data["tool"]["poetry"]["version"]


__version__ = get_version()
__all__ = ["tools", "dev", "PfLine", "PfState"]
Loading
Loading