-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Inconsistent return type for downsampling on resample of empty DataFrame #15093
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95d2008
BUG #14962
discort 8f7b437
BUG: added series type to wrap_result for empty DataFrame
discort 37ba820
added explicit 'size' method and defined logic there
discort 43b2613
fixed lint warnings
discort c0e06b8
Updated tests for resampling of empty dataframes
discort 44f52be
Fixed Jeff's comments
discort File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added explicit 'size' method and defined logic there
- Loading branch information
commit 37ba820ab2b59e258a9412cb7c0cf8d9723bd088
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1563,4 +1563,3 @@ Bug Fixes | |
- ``PeriodIndex`` can now accept ``list`` and ``array`` which contains ``pd.NaT`` (:issue:`13430`) | ||
- Bug in ``df.groupby`` where ``.median()`` returns arbitrary values if grouped dataframe contains empty bins (:issue:`13629`) | ||
- Bug in ``Index.copy()`` where ``name`` parameter was ignored (:issue:`14302`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert this file |
||
- Bug in ``_downsample()``. Inconsistent return type on resample of empty DataFrame (:issue:`14962`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from pandas.core.indexes.period import PeriodIndex, period_range | ||
import pandas.core.common as com | ||
import pandas.core.algorithms as algos | ||
from pandas.types.generic import ABCDataFrame | ||
|
||
import pandas.compat as compat | ||
from pandas.compat.numpy import function as nv | ||
|
@@ -549,7 +550,13 @@ def var(self, ddof=1, *args, **kwargs): | |
nv.validate_resampler_func('var', args, kwargs) | ||
return self._downsample('var', ddof=ddof) | ||
|
||
|
||
@Appender(GroupBy.size.__doc__) | ||
def size(self): | ||
# It 'seems' special and needs extra handling. GH14962 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better comment here. say its a special case as higher level does returns a copy of 0-len objects. |
||
result = self._downsample('size') | ||
if not len(self.ax) and isinstance(self._selected_obj, ABCDataFrame): | ||
result = pd.Series([], index=result.index, dtype='int64') | ||
return result | ||
Resampler._deprecated_valids += dir(Resampler) | ||
|
||
# downsample methods | ||
|
@@ -563,8 +570,7 @@ def f(self, _method=method, *args, **kwargs): | |
setattr(Resampler, method, f) | ||
|
||
# groupby & aggregate methods | ||
for method in ['count', 'size']: | ||
|
||
for method in ['count']: | ||
def f(self, _method=method): | ||
return self._downsample(_method) | ||
f.__doc__ = getattr(GroupBy, method).__doc__ | ||
|
@@ -770,14 +776,6 @@ def _wrap_result(self, result): | |
if self.kind == 'period' and not isinstance(result.index, PeriodIndex): | ||
result.index = result.index.to_period(self.freq) | ||
|
||
# Make consistent type of result. GH14962 | ||
if not len(self.ax): | ||
grouper = BinGrouper([], result.index) | ||
grouped = self._selected_obj.groupby(grouper) | ||
result = pd.Series([], | ||
index=result.index, | ||
name=grouped.name, | ||
dtype='int64') | ||
return result | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moves to 0.20.0
give a user friendly function here,
_downsample
is internal.