Skip to content

Commit a5be519

Browse files
authored
Merge pull request #536 from KevinShuman/534-chararray-dep
🧹 Updates cut_str() to avoid MyPy flagging depreciated np.chararray Issue #534
2 parents e19953e + 56a5156 commit a5be519

File tree

3 files changed

+740
-740
lines changed

3 files changed

+740
-740
lines changed

clouddrift/adapters/gdp/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,24 @@ def str_to_float(value: str, default: float = np.nan) -> float:
269269
return default
270270

271271

272-
def cut_str(value: str, max_length: int) -> np.chararray:
273-
"""Cut a string to a specific length and return it as a numpy chararray.
272+
def cut_str(value: str, max_length: int) -> np.ndarray:
273+
"""Cut a string to a specific length and return it as a NumPy array with fixed-length strings.
274274
275275
Parameters
276276
----------
277277
value : str
278-
String to cut
278+
String to cut.
279279
max_length : int
280-
Length of the output
280+
Maximum length of the output string.
281281
282282
Returns
283283
-------
284-
out : np.chararray
285-
String with max_length characters
284+
out : np.ndarray
285+
NumPy array containing the truncated string with fixed-length dtype.
286286
"""
287-
charar = np.chararray(1, max_length)
288-
charar[:max_length] = value
289-
return charar
287+
truncated_value = value[:max_length]
288+
char_array = np.array([truncated_value], dtype=f"<U{max_length}")
289+
return char_array
290290

291291

292292
def drogue_presence(lost_time, time) -> np.ndarray:

0 commit comments

Comments
 (0)