Skip to content

Update mean and sum functions #643

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

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
9 changes: 0 additions & 9 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -595,15 +595,6 @@
"contributions": [
"doc"
]
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing a contributor??

{
"login": "E105D104U125",
"name": "E69D68U85",
"avatar_url": "https://avatars.githubusercontent.com/u/72515278?v=4",
"profile": "https://github.com/E105D104U125",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to contributors should be made using the bot, please remove these files from the PR.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-52-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
## Contributors ✨

Expand Down Expand Up @@ -76,7 +76,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/psotom"><img src="https://avatars.githubusercontent.com/u/166627986?v=4?s=100" width="100px;" alt="psotom"/><br /><sub><b>psotom</b></sub></a><br /><a href="https://github.com/GAA-UAM/scikit-fda/commits?author=psotom" title="Code">💻</a> <a href="#example-psotom" title="Examples">💡</a> <a href="#ideas-psotom" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/GAA-UAM/scikit-fda/commits?author=psotom" title="Tests">⚠️</a> <a href="#research-psotom" title="Research">🔬</a> <a href="https://github.com/GAA-UAM/scikit-fda/commits?author=psotom" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/luisheb"><img src="https://avatars.githubusercontent.com/u/24703335?v=4?s=100" width="100px;" alt="Luis Hebrero"/><br /><sub><b>Luis Hebrero</b></sub></a><br /><a href="https://github.com/GAA-UAM/scikit-fda/commits?author=luisheb" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/E105D104U125"><img src="https://avatars.githubusercontent.com/u/72515278?v=4?s=100" width="100px;" alt="E69D68U85"/><br /><sub><b>E69D68U85</b></sub></a><br /><a href="https://github.com/GAA-UAM/scikit-fda/commits?author=E105D104U125" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
Expand Down
14 changes: 11 additions & 3 deletions skfda/representation/basis/_fdatabasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,15 @@ def sum( # noqa: WPS125
super().sum(axis=axis, out=out, keepdims=keepdims, skipna=skipna)

valid_functions = ~self.isna()
valid_counts = np.sum(valid_functions, axis=0)
valid_coefficients = self.coefficients[valid_functions]

coefs = np.sum(valid_coefficients, axis=0)
coefs = (
np.nansum(valid_coefficients, axis=0) if skipna
else np.sum(valid_coefficients, axis=0)
)

coefs = np.where(valid_counts >= min_count, coefs, np.nan)

return self.copy(
coefficients=coefs,
Expand All @@ -455,8 +461,9 @@ def mean( # noqa: WPS125
out: Used for compatibility with numpy. Must be None.
keepdims: Used for compatibility with numpy. Must be False.
skipna: Wether the NaNs are ignored or not.
min_count: Ignored, used for compatibility with FDataGrid
and FDataIrregular.
min_count: Number of valid (non NaN) data to have in order
for the a variable to not be NaN when `skipna` is
`True`.

Returns:
A FDataBasis object with just one sample representing
Expand All @@ -471,6 +478,7 @@ def mean( # noqa: WPS125
out=out,
keepdims=keepdims,
skipna=skipna,
min_count=min_count,
)
/ np.sum(~self.isna()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing comma. Otherwise, you are returning a tuple and the tests fail:

  • This is a number: (5)
  • This is a tuple: (5,)

)
Expand Down
2 changes: 1 addition & 1 deletion skfda/representation/irregular.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def mean( # noqa: WPS125
if skipna:
count_values = np.sum(~np.isnan(common_values), axis=0)
else:
count_values = np.full(sum_values.shape, self.n_samples)
count_values = self.n_samples

if min_count > 0 and skipna:
count_values[count_values < min_count] = np.nan
Expand Down
Loading