Skip to content

Commit 6b50943

Browse files
fix warnings in tests (#51)
* add pyarrow dep to fix tests * change delim_whitespace to sep='\s+' * add raw string formatter and change sep -> delimiter * Fix pandas FutureWarnings (#53) --------- Co-authored-by: Johannes Elferich <jojotux123@hotmail.com>
1 parent 49a1c09 commit 6b50943

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ classifiers = [
3838
dependencies = [
3939
"numpy",
4040
"pandas>=2.1.1",
41+
"pyarrow",
4142
"typing-extensions",
4243
]
4344

src/starfile/parser.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
if TYPE_CHECKING:
1616
from os import PathLike
1717

18+
def _apply_numeric(col: pd.Series) -> pd.Series:
19+
try:
20+
return pd.to_numeric(col)
21+
except ValueError:
22+
return col
1823

1924
class StarParser:
2025
filename: Path
@@ -104,15 +109,15 @@ def _parse_loop_block(self) -> pd.DataFrame:
104109
df = pd.DataFrame(np.zeros(shape=(0, n_cols)))
105110
else:
106111
df = pd.read_csv(
107-
StringIO(loop_data.replace("'",'"')),
108-
delim_whitespace=True,
112+
StringIO(loop_data.replace("'", '"')),
113+
delimiter=r'\s+',
109114
header=None,
110115
comment='#',
111116
keep_default_na=False
112117
)
113-
df_numeric = df.apply(pd.to_numeric, errors='ignore')
118+
df_numeric = df.apply(_apply_numeric)
114119
# Replace columns that are all NaN with the original string columns
115-
df_numeric.loc[:, df_numeric.isna().all()] = df.loc[:, df_numeric.isna().all()]
120+
df_numeric[df_numeric.columns[df_numeric.isna().all()]] = df[df_numeric.columns[df_numeric.isna().all()]]
116121
df = df_numeric
117122
df.columns = loop_column_names
118123
return df

0 commit comments

Comments
 (0)