Skip to content

Commit d2bb254

Browse files
committed
Use same data type for output as input
When cfs_to_cms is applied to a pandas dataframe on Windows, the output comes out as a numpy object. The changes enforce the output to be in same data type as the input.
1 parent 737993d commit d2bb254

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

vtools/functions/unit_conversions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,17 @@ def cfs_to_cms(x):
309309
-----
310310
1 ft³/s = 0.028316847 m³/s.
311311
"""
312-
arr = np.asarray(x)
313-
out = arr * CFS2CMS
314-
return out.item() if np.isscalar(x) else out
312+
313+
if isinstance(x, pd.DataFrame):
314+
# Element-wise multiply, preserving index/columns
315+
return x * CFS2CMS
316+
elif isinstance(x, pd.Series):
317+
# Preserve Series index and name
318+
return x * CFS2CMS
319+
else:
320+
arr = np.asarray(x)
321+
out = arr * CFS2CMS
322+
return out.item() if np.isscalar(x) else out
315323

316324

317325
def fahrenheit_to_celsius(x):

0 commit comments

Comments
 (0)