Skip to content

Commit

Permalink
Fixing pandas v2.1.0 compatibility (#126)
Browse files Browse the repository at this point in the history
* added constructor_from_mgr function
  • Loading branch information
JoschD authored Oct 31, 2023
1 parent 5dd087b commit c7f7fa9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# TFS-Pandas Changelog

## Version 3.7.2

- Fixed:
- fixing the issues with `pandas` >= `v2.1.0` (see `tfs-pandas` `v3.7.1`) by overwriting the `_constructor_from_mgr` function.

## Version 3.7.1

- Changed:
Expand Down
2 changes: 1 addition & 1 deletion 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,<2.1.0",
"pandas>=1.0",
]

# Extra dependencies
Expand Down
2 changes: 1 addition & 1 deletion 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.1"
__version__ = "3.7.2"
__author__ = "pylhc"
__author_email__ = "[email protected]"
__license__ = "MIT"
Expand Down
12 changes: 12 additions & 0 deletions tfs/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,19 @@ def __getattr__(self, name: str) -> object:

@property
def _constructor(self):
""" Function called, whenever a new ``TfsDataFrame`` is created
by pandas functionality, to ensure the new object is also a ``TfsDataFrame``.
"""
return TfsDataFrame

def _constructor_from_mgr(self, mgr, axes):
""" Initialize new ``TfsDataFrame`` from a dataframe manager.
This function is needed since pandas v2.1.0 to ensure the new object
given to __init__() already contains the headers.
See https://github.com/pandas-dev/pandas/issues/55120 """
obj = self._from_mgr(mgr, axes)
obj.headers = {}
return obj

def _headers_repr(self) -> str:
space: str = " " * 4
Expand Down

0 comments on commit c7f7fa9

Please sign in to comment.