-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Set frequency for empty Series #14458
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
Conversation
empty = Series(index=pd.DatetimeIndex([])).asfreq('H') | ||
normal = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), | ||
data=[3]).asfreq('H') | ||
self.assertEqual(empty.index.freq, normal.index.freq) |
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.
can u also test for TimedeltaIndex
and PeriodIndex
? The latter looks work properly, but for assurance.
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.
call these empty -> expected and normal -> result
use assert_index_equal
to compare
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.
@sinhrks should I add assert it for these types of indices in the same test or should I create separate tests for them?
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.
can u add to tserirs/tests/test_period(timedelras)
?
Codecov Report
@@ Coverage Diff @@
## master #14458 +/- ##
==========================================
- Coverage 91.04% 91.02% -0.03%
==========================================
Files 136 136
Lines 49088 49091 +3
==========================================
- Hits 44694 44685 -9
- Misses 4394 4406 +12
Continue to review full report at Codecov.
|
0bb68de
to
6d95b3a
Compare
doc/source/whatsnew/v0.19.1.txt
Outdated
is not scalar and ``values`` is not specified (:issue:`14380`) | ||
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` |
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.
You repeated here the previous entry
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.
can you move to 0.20.0
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.
Sure
expected = Series(index=pd.DatetimeIndex( | ||
["2016-09-29 11:00"])).asfreq('H') | ||
result = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), | ||
data=[3]).asfreq('H') |
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.
Can you create one of the two without using asfreq
.
Further, it is not fully clear what is what you actually testing, as the result of the empty series is called expected
(you typically call the constructed expected value expected
to compare the result of what you want to test)
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.
@jorisvandenbossche Actually the issue was that we didn't set frequency properly for empty series. Hence I'm testing this particular thing by comparing with frequency of a non-empty Series
that we make using similar parameters with an empty one.
@sahildua2305 Can you update? |
Got busy with stuff. I will update this soon @jorisvandenbossche |
can you rebase / update |
Yes, will do! |
f5e2400
to
f39a1bc
Compare
result = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), | ||
data=[3]).asfreq('H') | ||
self.assert_index_equal(expected.index, result.index) | ||
|
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.
compare the series, e.g. assert_series_equal
, and construct the expected directly.
you have two results to compare here, what you currently have labeled as expected and as result.
make another tests where you construct the expected directly (iow, dont' use .asfreq
) . IOW you actually should use a direc
pandas/tseries/tests/test_period.py
Outdated
@@ -1596,6 +1596,14 @@ def test_asfreq_mult(self): | |||
self.assertEqual(result.ordinal, expected.ordinal) | |||
self.assertEqual(result.freq, expected.freq) | |||
|
|||
def test_asfreq_period_empty_series(self): | |||
# GH 14340 | |||
expected = Series(index=pd.PeriodIndex(['2011-1', '2011-2', '2011-3'], |
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.
same here as above
can you rebase / update |
f39a1bc
to
1494d85
Compare
can you rebase / update |
Add test to verify frequency for empty series Update 0.19.1 whatsnew doc Fix linting; exceeded number of characters on one line Improve tests, add assertion for PeriodIndex as well Refactor tests and move to correct file Move changelog entry from 0.19.1 to 0.20.0
1494d85
to
384e666
Compare
thanks! |
closes pandas-dev#14320 Author: Sahil Dua <[email protected]> Closes pandas-dev#14458 from sahildua2305/frequency-series-fix and squashes the following commits: 384e666 [Sahil Dua] BUG: Set frequency for empty Series
git diff upstream/master | flake8 --diff
Alternative to #14340