Skip to content

Commit

Permalink
Fix xarray FutureWarning about dims vs sizes (#297)
Browse files Browse the repository at this point in the history
* use ds.sizes insted of ds.dims

* Change .dims to .sizes in kinematics tests

---------

Co-authored-by: sfmig <[email protected]>
  • Loading branch information
niksirbi and sfmig authored Sep 6, 2024
1 parent 95965f8 commit f4f46df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions tests/test_unit/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def test_interpolate_over_time_on_position(

# The number of NaNs after interpolating should be as expected
assert n_nans_after == (
valid_dataset_in_frames.dims["space"]
* valid_dataset_in_frames.dims.get("keypoints", 1)
valid_dataset_in_frames.sizes["space"]
* valid_dataset_in_frames.sizes.get("keypoints", 1)
# in bboxes dataset there is no keypoints dimension
* expected_n_nans_in_position
)
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_filter_by_confidence_on_position(
# the number of low confidence keypoints by the number of
# space dimensions
assert isinstance(position_filtered, xr.DataArray)
assert n_nans == valid_input_dataset.dims["space"] * n_low_confidence_kpts
assert n_nans == valid_input_dataset.sizes["space"] * n_low_confidence_kpts


@pytest.mark.parametrize(
Expand Down Expand Up @@ -198,15 +198,15 @@ def _assert_n_nans_in_position_per_individual(
# compute n nans in position after filtering per individual
n_nans_after_filtering_per_indiv = {
i: helpers.count_nans(position_filtered.isel(individuals=i))
for i in range(valid_input_dataset.dims["individuals"])
for i in range(valid_input_dataset.sizes["individuals"])
}

# check number of nans per indiv is as expected
for i in range(valid_input_dataset.dims["individuals"]):
for i in range(valid_input_dataset.sizes["individuals"]):
assert n_nans_after_filtering_per_indiv[i] == (
expected_nans_in_filt_position_per_indiv[i]
* valid_input_dataset.dims["space"]
* valid_input_dataset.dims.get("keypoints", 1)
* valid_input_dataset.sizes["space"]
* valid_input_dataset.sizes.get("keypoints", 1)
)

# Filter position
Expand Down
6 changes: 3 additions & 3 deletions tests/test_unit/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ def test_kinematics_with_dataset_with_nans(
# compute n nans in kinematic array per individual
n_nans_kinematics_per_indiv = [
helpers.count_nans(kinematic_array.isel(individuals=i))
for i in range(valid_dataset.dims["individuals"])
for i in range(valid_dataset.sizes["individuals"])
]

# expected nans per individual adjusted for space and keypoints dimensions
expected_nans_adjusted = [
n
* valid_dataset.dims["space"]
* valid_dataset.dims.get("keypoints", 1)
* valid_dataset.sizes["space"]
* valid_dataset.sizes.get("keypoints", 1)
for n in expected_nans_per_individual
]
# check number of nans per individual is as expected in kinematic array
Expand Down

0 comments on commit f4f46df

Please sign in to comment.