Skip to content

Commit 8eaa260

Browse files
Merge pull request #12 from gregory-halverson/main
fixing broadcasting
2 parents d87adb8 + 3aa0449 commit 8eaa260

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]
33

44
[project]
55
name = "solar-apparent-time"
6-
version = "1.5.0"
6+
version = "1.5.2"
77
description = "methods to translate Python datetime between solar apparent time and Coordinate Universal Time (UTC)"
88
readme = "README.md"
99
authors = [

solar_apparent_time/solar_apparent_time.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,21 @@ def calculate_solar_day_of_year(
163163
elif lon is None:
164164
raise ValueError("no longitude provided")
165165

166-
# Broadcast times and lons
167-
times_b, lons_b = _broadcast_time_and_space(times, lon)
166+
# Handle 1D time and lon inputs of the same length: pair element-wise
167+
times = np.asarray(times)
168+
lon = np.asarray(lon)
169+
if times.ndim == 1 and lon.ndim == 1 and times.shape == lon.shape:
170+
times_b = times
171+
lons_b = lon
172+
else:
173+
# Broadcast to 2D if not matching 1D
174+
times_b, lons_b = _broadcast_time_and_space(times, lon)
175+
168176
# Vectorized conversion to pandas datetime and dayofyear extraction
169177
times_b_flat = times_b.flatten()
170178
times_b_dt = pd.to_datetime(times_b_flat)
171179
doy_UTC = times_b_dt.dayofyear.values.reshape(times_b.shape)
172-
180+
173181
hour_UTC = (
174182
times_b.astype('datetime64[h]').astype(int) % 24
175183
+ (times_b.astype('datetime64[m]').astype(int) % 60) / 60

0 commit comments

Comments
 (0)