Skip to content

Commit

Permalink
Merge pull request #14 from AI-sandbox/fix-mspreader-bug
Browse files Browse the repository at this point in the history
Fix MSPreader bug related to dtype of chromosomes
  • Loading branch information
salcc authored Nov 26, 2024
2 parents ffea32c + 5b57d7e commit 1b208a9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions snputils/ancestry/io/local/read/msp.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -96,8 +95,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':
Expand Down

0 comments on commit 1b208a9

Please sign in to comment.