Skip to content

Commit 817557a

Browse files
authored
refactor: adapt code to work with pandas 3
2 parents f5eab69 + 09d790e commit 817557a

5 files changed

Lines changed: 31 additions & 16 deletions

File tree

.github/workflows/doc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
beautifulsoup4
5353
shapely
5454
geopandas
55-
pyinterp
55+
pyinterp<2026.2.0
5656
dask
5757
- name: Install package (for autodoc)
5858
shell: bash -l {0}

.github/workflows/tests.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
pyftpdlib
4141
shapely
4242
geopandas
43-
pyinterp
43+
pyinterp<2026.2.0
4444
dask
4545
- name: Install python dependencies
4646
shell: bash -el {0}
@@ -51,7 +51,7 @@ jobs:
5151
- name: Run unit tests
5252
shell: bash -el {0}
5353
run: |
54-
pytest tests --cov=src --cov-report=xml:coverage-ut.xml --cov-report=term
54+
pytest tests --cov=src/fcollections --cov-report=xml:coverage-ut.xml --cov-report=term
5555
mv .coverage .coverage-ut
5656
- name: Upload unit test coverage artifacts
5757
uses: actions/upload-artifact@v4
@@ -94,7 +94,7 @@ jobs:
9494
pyftpdlib
9595
shapely
9696
geopandas
97-
pyinterp
97+
pyinterp<2026.2.0
9898
dask
9999
- name: Install python dependencies
100100
shell: bash -el {0}
@@ -104,7 +104,7 @@ jobs:
104104
- name: Run unit tests without geo
105105
shell: bash -el {0}
106106
run: |
107-
pytest tests/implementations/collections --ignore tests/implementations/collections/test_area_selector.py --without-geo-packages --cov=src --cov-report=xml:coverage-ut-nogeo.xml --cov-report=term
107+
pytest tests/implementations/collections --ignore tests/implementations/collections/test_area_selector.py --without-geo-packages --cov=src/fcollections --cov-report=xml:coverage-ut-nogeo.xml --cov-report=term
108108
mv .coverage .coverage-ut-nogeo
109109
- name: Upload unit test no-geo coverage artifacts
110110
uses: actions/upload-artifact@v4
@@ -129,7 +129,7 @@ jobs:
129129
pip install -e ".[testing]"
130130
- name: Run integration tests
131131
run: |
132-
pytest integration_tests --cov=src --cov-report=xml:coverage-it.xml --cov-report=term
132+
pytest integration_tests --cov=src/fcollections --cov-report=xml:coverage-it.xml --cov-report=term
133133
mv .coverage .coverage-it
134134
- name: Upload integration test coverage artifacts
135135
uses: actions/upload-artifact@v4

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ maintainers = [
1010
{name = "Robin Chevrier", email = "rchevrier@groupcls.com"},
1111
{name = "Anne-Sophie Tonneau", email = "atonneau@groupcls.com"}
1212
]
13-
requires-python = ">= 3.8"
13+
requires-python = ">= 3.11"
1414
readme = "README.md"
1515
dependencies = [
1616
"docstring_parser",
1717
"fsspec",
1818
"jinja2",
1919
"netCDF4",
2020
"numpy",
21+
"pandas>=3",
2122
"requests",
2223
"typer",
2324
"xarray[io]"]
@@ -48,7 +49,7 @@ Repository='https://github.com/robin-cls/fcollections'
4849

4950
[project.optional-dependencies]
5051
testing = ["pytest", "pytest-cov", "sympy", "beautifulsoup4", "pyftpdlib", "pyasynchat"]
51-
geo = ["shapely", "geopandas", "pyinterp", "dask", "numba"]
52+
geo = ["shapely", "geopandas", "pyinterp<2026.2.0", "dask", "numba"]
5253
doc = ["cartopy", "matplotlib", "sphinx", "sphinx-copybutton", "sphinx-design",
5354
"sphinx-book-theme", "myst-nb"]
5455

src/fcollections/core/_filesdb.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,18 @@ def __call__(self, df: pda.DataFrame) -> pda.DataFrame:
690690
)
691691
except AttributeError:
692692
# We have a tuple
693-
subsets = df.groupby(list(self.partition_keys))
693+
grouping_keys = list(self.partition_keys)
694+
subsets = df.groupby(
695+
# In pandas 2, a list with one single element gave a scalar keys
696+
# for the groups. In pandas 3, a future warning is raised,
697+
# asking to give either a single key or a list with more than
698+
# one key
699+
grouping_keys if len(grouping_keys) > 1 else grouping_keys[0],
700+
# Pandas 3 tries to sort the groups, which can raise an error if
701+
# a column cannot be ordered. We don't need this sort so we
702+
# disable it
703+
sort=False,
704+
)
694705

695706
# Pick one subset using panda duplicate handling
696707
subset_names = [
@@ -719,11 +730,14 @@ def __call__(self, df: pda.DataFrame) -> pda.DataFrame:
719730
for key in manual_pick
720731
if len(df_subsets[key].unique()) > 1
721732
}
722-
raise ValueError(
723-
f"Subsets could not be unmixed, the following keys are duplicated and should be fixed manually: {ambiguity}"
733+
msg = (
734+
"Subsets could not be unmixed, the following keys are "
735+
f"duplicated and should be fixed manually: {ambiguity}"
724736
)
737+
raise ValueError(msg)
725738

726739
group_name = tuple(df_subsets.to_records(index=False)[-1])
740+
group_name = group_name if len(group_name) > 1 else group_name[0]
727741
logger.debug("Subset selected %s", group_name)
728742
return subsets.get_group(group_name)
729743

tests/core/test_filesdb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ def test_metadata_wrong_filters(tmp_path: Path):
315315
def test_list_files(db_with_files: FilesDatabaseTest):
316316
expected = pda.DataFrame(
317317
[
318-
(np.datetime64("2025-01-01"), 1, "/flat/a_file_001_20250101.nc"),
319-
(np.datetime64("2025-01-01"), 2, "/flat/a_file_002_20250101.nc"),
318+
(np.datetime64("2025-01-01", "us"), 1, "/flat/a_file_001_20250101.nc"),
319+
(np.datetime64("2025-01-01", "us"), 2, "/flat/a_file_002_20250101.nc"),
320320
],
321321
columns=["time", "a_number", "filename"],
322322
)
@@ -325,7 +325,7 @@ def test_list_files(db_with_files: FilesDatabaseTest):
325325

326326
def test_list_files_filter(db_with_files: FilesDatabaseTest):
327327
expected = pda.DataFrame(
328-
[(np.datetime64("2025-01-01"), 2, "/flat/a_file_002_20250101.nc")],
328+
[(np.datetime64("2025-01-01", "us"), 2, "/flat/a_file_002_20250101.nc")],
329329
columns=["time", "a_number", "filename"],
330330
)
331331
assert expected.equals(db_with_files.list_files(a_number=2))
@@ -352,8 +352,8 @@ def test_list_files_predicate(
352352
):
353353
expected = pda.DataFrame(
354354
[
355-
(np.datetime64("2025-01-01"), 2, "/predicate/a_file_002_20250101.nc"),
356-
(np.datetime64("2025-01-01"), 4, "/predicate/a_file_004_20250101.nc"),
355+
(np.datetime64("2025-01-01", "us"), 2, "/predicate/a_file_002_20250101.nc"),
356+
(np.datetime64("2025-01-01", "us"), 4, "/predicate/a_file_004_20250101.nc"),
357357
],
358358
columns=["time", "a_number", "filename"],
359359
)

0 commit comments

Comments
 (0)