Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSPreader bug related to dtype of chromosomes #14

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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