From 071ba05efa779457f92079f2ba5ff6992e940bad Mon Sep 17 00:00:00 2001 From: Tom Kingstone Date: Thu, 29 Oct 2026 09:52:45 +0000 Subject: [PATCH 1/2] remove the borg (the unintentionally used borg design pattern) --- .../src/python_toolkit/bhom/bhom_object.py | 16 ++++++++-------- .../Python/src/python_toolkit/bhom/util.py | 10 ++++++---- .../src/python_toolkit/plot/cmap_sample.py | 6 ++++-- .../plot/parallel_coordinate_plot.py | 2 +- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Python_Engine/Python/src/python_toolkit/bhom/bhom_object.py b/Python_Engine/Python/src/python_toolkit/bhom/bhom_object.py index 10785de5..48a05ae7 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom/bhom_object.py +++ b/Python_Engine/Python/src/python_toolkit/bhom/bhom_object.py @@ -237,19 +237,19 @@ def __init__( self, _t: str, #don't make default, as subclasses of this class should set this with super().__init__ name: str = "", - bhom_guid: uuid.UUID = uuid.uuid4(), - tags: List[str] = [], - fragments: List[Dict[str, object]] = [], - custom_data: Dict[str, object] = {}, + bhom_guid: uuid.UUID = None, + tags: List[str] = None, + fragments: List[Dict[str, object]] = None, + custom_data: Dict[str, object] = None, _bhom_version: str = None, **kwargs ) -> 'BHoMObject': self._t = _t self.name = name - self.bhom_guid = bhom_guid - self.fragments = fragments - self.tags = tags - self.custom_data = custom_data + self.bhom_guid = bhom_guid or uuid.uuid4() + self.fragments = fragments or [] + self.tags = tags or [] + self.custom_data = custom_data or {} self._bhom_version = _bhom_version #set non-CustomData properties with reflection. diff --git a/Python_Engine/Python/src/python_toolkit/bhom/util.py b/Python_Engine/Python/src/python_toolkit/bhom/util.py index 1c06ab0d..1908a3f5 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom/util.py +++ b/Python_Engine/Python/src/python_toolkit/bhom/util.py @@ -1,20 +1,22 @@ """General utility functions.""" # pylint: disable=E0401 -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone # pylint: enable=E0401 -def bson_unix_ticks(date_time: datetime = datetime.utcnow(), short: bool = False) -> int: +def bson_unix_ticks(date_time: datetime = None, short: bool = False) -> int: """Python implementation of unix ticks. Args: - date_time (datetime, optional): The datetime to convert to ticks. Defaults to datetime.utcnow(). + date_time (datetime, optional): The datetime to convert to ticks. Defaults to datetime.now(timezone.utc). short (bool, optional): Whether to return the short ticks. Defaults to False. Returns: int: The ticks. """ + date_time = date_time or datetime.now(timezone.utc) + _ticks = (date_time - datetime(1970, 1, 1)).total_seconds() * 10**3 if short: @@ -27,5 +29,5 @@ def bson_unix_ticks_to_datetime(ticks: int, short:bool = False) -> datetime: if not short: ticks = int(ticks / (10**3)) - return datetime(1970, 1, 1) + timedelta(milliseconds=ticks) + return datetime(1970, 1, 1, tzinfo=timezone.utc) + timedelta(milliseconds=ticks) diff --git a/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py b/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py index 89079214..9b1d0e3b 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py +++ b/Python_Engine/Python/src/python_toolkit/plot/cmap_sample.py @@ -9,7 +9,7 @@ def cmap_sample_plot( cmap: Union[str, Colormap], bounds: Optional[tuple] = None, - figsize: tuple = (9, 1), + figsize: Optional[tuple] = None, bins: int = 256 ) -> Figure: @@ -19,12 +19,14 @@ def cmap_sample_plot( Args: cmap: Either a colormap string (e.g., 'viridis') or a custom Colormap object bounds: Optional tuple of (vmin, vmax) for normalization. If None, uses (0, 1) - figsize: Figure size as (width, height) + figsize: Figure size as (width, height). If None, defaults to (9, 1) bins: Number of discrete bins for the gradient. Defaults to 256. Returns: Matplotlib Figure object """ + figsize = figsize or (9, 1) + # Set bounds if bounds is None: bounds = (0, 1) diff --git a/Python_Engine/Python/src/python_toolkit/plot/parallel_coordinate_plot.py b/Python_Engine/Python/src/python_toolkit/plot/parallel_coordinate_plot.py index 60c1d86f..f3080ce0 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/parallel_coordinate_plot.py +++ b/Python_Engine/Python/src/python_toolkit/plot/parallel_coordinate_plot.py @@ -69,7 +69,7 @@ def set_dimensions(df: pd.DataFrame, tick_mark_count: int, dp:int) -> List[Dict[ @bhom_analytics() def parallel_coordinate_plot( - df: pd.DataFrame = pd.DataFrame(), + df: pd.DataFrame, variables_to_show: list = None, decimal_places: int = 0, tick_mark_count: int = 11, From 6db0bb69fc6399096a918f224dfe49c5b9d2ac88 Mon Sep 17 00:00:00 2001 From: Tom Kingstone Date: Thu, 29 Oct 2026 10:16:47 +0000 Subject: [PATCH 2/2] fix extra deprecation issues and failing tests --- Python_Engine/Python/src/python_toolkit/bhom/analytics.py | 4 ++-- Python_Engine/Python/src/python_toolkit/bhom/util.py | 2 +- Python_Engine/Python/src/python_toolkit/plot/diurnal.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Python_Engine/Python/src/python_toolkit/bhom/analytics.py b/Python_Engine/Python/src/python_toolkit/bhom/analytics.py index 7ba81cb9..0078c540 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom/analytics.py +++ b/Python_Engine/Python/src/python_toolkit/bhom/analytics.py @@ -14,7 +14,7 @@ import uuid from functools import wraps from typing import Any, Callable, Dict, List, Union -from datetime import datetime +from datetime import datetime, timezone # pylint: enable=E0401 @@ -107,7 +107,7 @@ def summarise_usage_logs(usage_log_entries:List[UsageLogEntry]) -> List[Dict]: return db_entries def convert_exc_info_to_bhom_error(exc_info): - time = bson_unix_ticks(datetime.now(), short=True) + time = bson_unix_ticks(datetime.now(timezone.utc), short=True) utcTime = bson_unix_ticks(short=True) stack_trace = traceback.extract_tb(exc_info[2]) message = str(exc_info[1]) diff --git a/Python_Engine/Python/src/python_toolkit/bhom/util.py b/Python_Engine/Python/src/python_toolkit/bhom/util.py index 1908a3f5..587225c5 100644 --- a/Python_Engine/Python/src/python_toolkit/bhom/util.py +++ b/Python_Engine/Python/src/python_toolkit/bhom/util.py @@ -17,7 +17,7 @@ def bson_unix_ticks(date_time: datetime = None, short: bool = False) -> int: date_time = date_time or datetime.now(timezone.utc) - _ticks = (date_time - datetime(1970, 1, 1)).total_seconds() * 10**3 + _ticks = (date_time - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds() * 10**3 if short: return int(_ticks) diff --git a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py index ed42fdaf..2099bd8b 100644 --- a/Python_Engine/Python/src/python_toolkit/plot/diurnal.py +++ b/Python_Engine/Python/src/python_toolkit/plot/diurnal.py @@ -99,7 +99,7 @@ def diurnal( minor_ticks = target_idx major_ticklabels = [f"{i:02d}:00" for i in major_ticks] elif period == "weekly": - group = series.groupby([series.index.dayofweek, series.index.hour]) + group = series.groupby([series.index.day_of_week, series.index.hour]) target_idx = pd.MultiIndex.from_product([range(7), range(24)]) major_ticks = range(len(target_idx))[::12] minor_ticks = range(len(target_idx))[::3]