Skip to content

Deprecations and FutureWarnings Fixes #128

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

Merged
merged 14 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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__"]
2 changes: 1 addition & 1 deletion tfs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Advanced **TFS** files reading and writing functionality.
"""
from typing import Tuple, List, Dict
from typing import Tuple, Dict

import pathlib

Expand Down
9 changes: 7 additions & 2 deletions tfs/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions tfs/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tfs/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down