From 555adb78ff1fe4b1f9d0178439bf10ca6af4acc0 Mon Sep 17 00:00:00 2001 From: miriambt Date: Mon, 25 Nov 2024 18:00:59 -0500 Subject: [PATCH 1/2] Fix bug in MSPReader related to string chromosomes --- snputils/ancestry/io/local/read/msp.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/snputils/ancestry/io/local/read/msp.py b/snputils/ancestry/io/local/read/msp.py index 07e5675..f0a6076 100644 --- a/snputils/ancestry/io/local/read/msp.py +++ b/snputils/ancestry/io/local/read/msp.py @@ -96,8 +96,15 @@ def _replace_nan_with_none(self, array: Optional[np.ndarray]) -> Optional[np.nda Returns: Optional[np.ndarray]: Returns `None` if the array is fully NaN, otherwise returns the original array. """ - if array is not None and np.isnan(array).all(): - return None + if array is not None: + if array.size == 0: # Check if the array is empty + return None + if np.issubdtype(array.dtype, np.number): # Check for numeric types + if np.isnan(array).all(): # Fully NaN numeric array + return None + elif array.dtype == np.object_ or np.issubdtype(array.dtype, np.str_): # String or object types + if all(elem == '' or elem is None for elem in array): # Empty or None strings + return None return array def read(self) -> 'LocalAncestryObject': From 5b57d7e6f28619374a011f09ed93f8de6e756448 Mon Sep 17 00:00:00 2001 From: miriambt Date: Mon, 25 Nov 2024 18:02:43 -0500 Subject: [PATCH 2/2] Optimize import --- snputils/ancestry/io/local/read/msp.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/snputils/ancestry/io/local/read/msp.py b/snputils/ancestry/io/local/read/msp.py index f0a6076..1e5ffee 100644 --- a/snputils/ancestry/io/local/read/msp.py +++ b/snputils/ancestry/io/local/read/msp.py @@ -1,10 +1,9 @@ from pathlib import Path -from typing import List, Dict, Optional +from typing import List, Dict, Optional, Union import logging import warnings import numpy as np import pandas as pd -from typing import Union from .base import LAIBaseReader from snputils.ancestry.genobj.local import LocalAncestryObject