Skip to content

Commit c7f7fa9

Browse files
authored
Fixing pandas v2.1.0 compatibility (#126)
* added constructor_from_mgr function
1 parent 5dd087b commit c7f7fa9

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# TFS-Pandas Changelog
22

3+
## Version 3.7.2
4+
5+
- Fixed:
6+
- fixing the issues with `pandas` >= `v2.1.0` (see `tfs-pandas` `v3.7.1`) by overwriting the `_constructor_from_mgr` function.
7+
38
## Version 3.7.1
49

510
- Changed:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:
3030
# Dependencies for the package itself
3131
DEPENDENCIES = [
3232
"numpy>=1.19.0",
33-
"pandas>=1.0,<2.1.0",
33+
"pandas>=1.0",
3434
]
3535

3636
# Extra dependencies

tfs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
__title__ = "tfs-pandas"
1111
__description__ = "Read and write tfs files."
1212
__url__ = "https://github.com/pylhc/tfs"
13-
__version__ = "3.7.1"
13+
__version__ = "3.7.2"
1414
__author__ = "pylhc"
1515
__author_email__ = "[email protected]"
1616
__license__ = "MIT"

tfs/frame.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@ def __getattr__(self, name: str) -> object:
5858

5959
@property
6060
def _constructor(self):
61+
""" Function called, whenever a new ``TfsDataFrame`` is created
62+
by pandas functionality, to ensure the new object is also a ``TfsDataFrame``.
63+
"""
6164
return TfsDataFrame
65+
66+
def _constructor_from_mgr(self, mgr, axes):
67+
""" Initialize new ``TfsDataFrame`` from a dataframe manager.
68+
This function is needed since pandas v2.1.0 to ensure the new object
69+
given to __init__() already contains the headers.
70+
See https://github.com/pandas-dev/pandas/issues/55120 """
71+
obj = self._from_mgr(mgr, axes)
72+
obj.headers = {}
73+
return obj
6274

6375
def _headers_repr(self) -> str:
6476
space: str = " " * 4

0 commit comments

Comments
 (0)