diff --git a/setup.py b/setup.py index 22bdd5e4..53187f54 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict: # Dependencies for the package itself DEPENDENCIES = [ "numpy>=1.19.0", - "pandas>=1.0", + "pandas>=2.1", ] # Extra dependencies @@ -53,7 +53,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict: url=ABOUT_TFS["__url__"], packages=setuptools.find_packages(include=(MODULE_NAME,)), include_package_data=True, - python_requires=">=3.7", + python_requires=">=3.9", license=ABOUT_TFS["__license__"], classifiers=[ "Development Status :: 5 - Production/Stable", diff --git a/tfs/__init__.py b/tfs/__init__.py index 1a963490..d5b413e9 100644 --- a/tfs/__init__.py +++ b/tfs/__init__.py @@ -10,7 +10,7 @@ __title__ = "tfs-pandas" __description__ = "Read and write tfs files." __url__ = "https://github.com/pylhc/tfs" -__version__ = "3.7.3" +__version__ = "3.8.0" __author__ = "pylhc" __author_email__ = "pylhc@github.com" __license__ = "MIT" @@ -19,4 +19,4 @@ read = read_tfs write = write_tfs -__all__ = [concat, read, write, read_hdf, write_hdf, TfsDataFrame, __version__] +__all__ = ["concat", "read", "write", "read_hdf", "write_hdf", "TfsDataFrame", "TfsFormatError", "__version__"] diff --git a/tfs/collection.py b/tfs/collection.py index 51780161..c863616c 100644 --- a/tfs/collection.py +++ b/tfs/collection.py @@ -4,7 +4,7 @@ Advanced **TFS** files reading and writing functionality. """ -from typing import Tuple, List, Dict +from typing import Tuple, Dict import pathlib diff --git a/tfs/frame.py b/tfs/frame.py index 72beae84..c01a6a19 100644 --- a/tfs/frame.py +++ b/tfs/frame.py @@ -263,8 +263,13 @@ def _element_is_list(element): raise TfsFormatError("Lists or tuple elements are not accepted in a TfsDataFrame") # ----- Check that no element is non-physical value in the dataframe ----- # - with pd.option_context('mode.use_inf_as_na', True): - inf_or_nan_bool_df = data_frame.isna() + # The pd.option_context('mode.use_inf_as_na', True) context manager raises FutureWarning + # and will likely disappear in pandas 3.0 so we replace 'inf' values by NaNs before calling + # .isna(). Additionally, the downcasting behaviour of .replace() is deprecated and raises a + # FutureWarning, so we use .infer_objects() first to attemps soft conversion to a better dtype + # for object-dtype columns (which strings can be). Since .infer_objects() and .replace() return + # (lazy for the former) copies we're not modifying the original dataframe during validation :) + inf_or_nan_bool_df = data_frame.infer_objects().replace([np.inf, -np.inf], np.nan).isna() if inf_or_nan_bool_df.to_numpy().any(): LOGGER.warning( diff --git a/tfs/reader.py b/tfs/reader.py index 27f2b55e..ad3d4c12 100644 --- a/tfs/reader.py +++ b/tfs/reader.py @@ -135,8 +135,7 @@ def read_tfs( tfs_file_path, engine="c", # faster, and we do not need the features of the python engine skiprows=metadata.non_data_lines, # no need to read these lines again - delim_whitespace=True, # understands ' ' is our delimiter - skipinitialspace=True, # understands ' ' and ' ' are both valid delimiters + sep=r"\s+", # understands ' ' as delimiter | replaced deprecated 'delim_whitespace' in tfs-pandas 3.8.0 quotechar='"', # elements surrounded by " are one entry -> correct parsing of strings with spaces names=metadata.column_names, # column names we have determined, avoids using first read row for columns dtype=dict( diff --git a/tfs/writer.py b/tfs/writer.py index a2d16af9..b77872a1 100644 --- a/tfs/writer.py +++ b/tfs/writer.py @@ -241,7 +241,7 @@ def quote_strings(s): return f'"{s}"' return s - data_frame = data_frame.applymap(quote_strings) + data_frame = data_frame.map(quote_strings) return data_frame