Skip to content
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ requires-python = ">=3.11"
dependencies = [
"psycopg>=3.1.10,<4.0",
"sqlalchemy>=2.0.8,<3.0",
"pandas>=2.2,<3.0",
"pandas>=3.0.0,<4.0",
"pint>=0.23.0",
"argon2_cffi>=23.1.0",
"alembic>=1.8.0,<2.0",
"click>=8.1.3,<9.0",
"celery>=5.3.1,<6.0",
"redis>=4.3.4,<5.0",
"redis>=7.4.0,<8.0",
"requests>=2.28.2",
]

Expand Down
4 changes: 2 additions & 2 deletions requirements/install-min.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
psycopg==3.1.10
sqlalchemy==2.0.8
pandas==2.2
pandas==3.0.0
argon2_cffi==23.1.0
alembic==1.8.0
click==8.1.3
celery==5.3.1
redis==4.3.4
redis==7.4.0
pint==0.23.0
requests==2.28.2
15 changes: 3 additions & 12 deletions requirements/install-min.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ click-plugins==1.1.1.2
# via celery
click-repl==0.3.0
# via celery
deprecated==1.3.1
# via redis
greenlet==3.4.0
# via sqlalchemy
idna==3.11
Expand All @@ -52,10 +50,8 @@ markupsafe==3.0.3
numpy==1.26.4
# via pandas
packaging==26.1
# via
# kombu
# redis
pandas==2.2.0
# via kombu
pandas==3.0.0
# via -r requirements/install-min.in
pint==0.23
# via -r requirements/install-min.in
Expand All @@ -69,9 +65,7 @@ python-dateutil==2.9.0.post0
# via
# celery
# pandas
pytz==2026.1.post1
# via pandas
redis==4.3.4
redis==7.4.0
# via -r requirements/install-min.in
requests==2.28.2
# via -r requirements/install-min.in
Expand All @@ -90,7 +84,6 @@ tzdata==2026.1
# via
# celery
# kombu
# pandas
urllib3==1.26.20
# via requests
vine==5.1.0
Expand All @@ -100,5 +93,3 @@ vine==5.1.0
# kombu
wcwidth==0.6.0
# via prompt-toolkit
wrapt==2.1.2
# via deprecated
10 changes: 3 additions & 7 deletions requirements/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ numpy==2.4.4
# via pandas
packaging==26.1
# via kombu
pandas==2.3.3
pandas==3.0.2
# via bemserver-core (pyproject.toml)
pint==0.25.3
# via bemserver-core (pyproject.toml)
Expand All @@ -71,9 +71,7 @@ python-dateutil==2.9.0.post0
# via
# celery
# pandas
pytz==2026.1.post1
# via pandas
redis==4.6.0
redis==7.4.0
# via bemserver-core (pyproject.toml)
requests==2.33.1
# via bemserver-core (pyproject.toml)
Expand All @@ -92,9 +90,7 @@ typing-extensions==4.15.0
# psycopg
# sqlalchemy
tzdata==2026.1
# via
# kombu
# pandas
# via kombu
tzlocal==5.3.1
# via celery
urllib3==2.6.3
Expand Down
5 changes: 0 additions & 5 deletions src/bemserver_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import os

import pandas as pd

from bemserver_core import (
common,
database,
Expand All @@ -18,9 +16,6 @@
from bemserver_core.exceptions import BEMServerCoreSettingsError
from bemserver_core.process.weather import wdp

# Set pandas future flags to silence deprecation warnings
pd.set_option("future.no_silent_downcasting", True)


class BEMServerCore:
def __init__(self):
Expand Down
17 changes: 12 additions & 5 deletions src/bemserver_core/input_output/timeseries_data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ def get_timeseries_data(
data, columns=("timestamp", "id", "name", "value")
).set_index("timestamp")
data_df["value"] = data_df["value"].astype(float)
data_df.index = pd.DatetimeIndex(data_df.index, tz="UTC").tz_convert(
ZoneInfo(timezone)
data_df.index = (
pd.DatetimeIndex(data_df.index, tz="UTC")
.as_unit("us")
.tz_convert(ZoneInfo(timezone))
)

data_df = data_df.pivot(columns=col_label, values="value")
Expand Down Expand Up @@ -482,7 +484,9 @@ def get_timeseries_buckets_data(
)

if not timeseries:
return pd.DataFrame({}, index=complete_idx)
ret_df = pd.DataFrame({}, index=complete_idx)
ret_df.columns.name = col_label
return ret_df

# At this stage, date_trunc can only aggregate by 1 x unit.
# For a N x width bucket size, the remaining aggregation is
Expand Down Expand Up @@ -513,7 +517,9 @@ def get_timeseries_buckets_data(
data, columns=("timestamp", "id", "name", "value")
).set_index("timestamp")

data_df.index = pd.DatetimeIndex(data_df.index, tz="UTC").tz_convert(tz_info)
data_df.index = (
pd.DatetimeIndex(data_df.index, tz="UTC").as_unit("us").tz_convert(tz_info)
)

# Pivot table to get timeseries in columns
data_df = data_df.pivot(values="value", columns=col_label).fillna(fill_value)
Expand Down Expand Up @@ -652,6 +658,7 @@ def delete(cls, start_dt, end_dt, timeseries, data_state):

def to_utc_index(index):
"""Create UTC datetime index from timezone aware datetime list"""
# https://github.com/pandas-dev/pandas/issues/54995

try:
# Cast to series so that output is series, with an apply method
Expand All @@ -669,7 +676,7 @@ def to_utc_index(index):
except TypeError as exc:
raise TimeseriesDataIODatetimeError("Invalid or TZ-naive timestamp") from exc

return pd.DatetimeIndex(index, name="timestamp")
return pd.DatetimeIndex(index, name="timestamp").as_unit("us")


class TimeseriesDataCSVIO(TimeseriesDataIO, BaseCSVIO):
Expand Down
6 changes: 3 additions & 3 deletions src/bemserver_core/process/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def cleanup(
ts_mins = Timeseries.get_property_for_many_timeseries(timeseries_ids, "Min")
ts_maxs = Timeseries.get_property_for_many_timeseries(timeseries_ids, "Max")

for ts_id, (_, col) in zip(timeseries_ids, data_df.items(), strict=True):
for ts_id in timeseries_ids:
if (ts_min := ts_mins[ts_id]) is not None:
col.loc[col < float(ts_min)] = np.nan
data_df.loc[data_df[ts_id] < float(ts_min), ts_id] = np.nan
if (ts_max := ts_maxs[ts_id]) is not None:
col.loc[col > float(ts_max)] = np.nan
data_df.loc[data_df[ts_id] > float(ts_max), ts_id] = np.nan

return data_df
2 changes: 1 addition & 1 deletion src/bemserver_core/process/energy_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def energyindex2power(
power_s = power_s.resample(pd_freq, closed="left", label="left").agg("mean")

# Convert to desired unit
convert_from = ureg.validate_unit(index_ts.unit_symbol) / ureg.validate_unit("ns")
convert_from = ureg.validate_unit(index_ts.unit_symbol) / ureg.validate_unit("us")
power_s = pd.Series(
ureg.convert(power_s.values, convert_from, convert_to),
index=power_s.index,
Expand Down
2 changes: 1 addition & 1 deletion src/bemserver_core/process/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def get_weather_data(
index=pd.DatetimeIndex(
pd.to_datetime(timestamps, utc=True, unit="s"),
name="timestamp",
),
).as_unit("us"),
data=ret_data["data"],
# Strip (unit) from column names to facilitate selection
columns=[str(col).split()[0] for col in ret_data["columns"]],
Expand Down
3 changes: 2 additions & 1 deletion tests/common/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

import pandas as pd
from pandas.testing import assert_frame_equal

from bemserver_core import BEMServerCore
from bemserver_core.common import ureg
Expand Down Expand Up @@ -66,7 +67,7 @@ def test_ureg_convert_dimensionality_error(self):
def test_ureg_convert_df(self):
data_df = pd.DataFrame({"id": [0, 1, 2]})
ureg.convert_df(data_df, {"id": "km"}, {"id": "m"})
assert data_df.equals(1000.0 * pd.DataFrame({"id": [0, 1, 2]}))
assert_frame_equal(data_df, (1000.0 * pd.DataFrame({"id": [0, 1, 2]})))

def test_ureg_convert_df_undefined_unit(self):
data_df = pd.DataFrame({"id": [0, 1, 2]})
Expand Down
Loading
Loading