Skip to content

Commit

Permalink
Fix pandas FutureWarnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoelfe committed Feb 22, 2024
1 parent d790fba commit a42324f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/starfile/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
if TYPE_CHECKING:
from os import PathLike

def _apply_numeric(col: pd.Series) -> pd.Series:
try:
return pd.to_numeric(col)
except ValueError:
return col

class StarParser:
filename: Path
Expand Down Expand Up @@ -110,9 +115,9 @@ def _parse_loop_block(self) -> pd.DataFrame:
comment='#',
keep_default_na=False
)
df_numeric = df.apply(pd.to_numeric, errors='ignore')
df_numeric = df.apply(_apply_numeric)
# Replace columns that are all NaN with the original string columns
df_numeric.loc[:, df_numeric.isna().all()] = df.loc[:, df_numeric.isna().all()]
df_numeric[df_numeric.columns[df_numeric.isna().all()]] = df[df_numeric.columns[df_numeric.isna().all()]]
df = df_numeric
df.columns = loop_column_names
return df
Expand Down

0 comments on commit a42324f

Please sign in to comment.