Skip to content

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

Closed

Conversation

sahildua2305
Copy link
Contributor

Alternative to #14340

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)
Copy link
Member

@sinhrks sinhrks Oct 20, 2016

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.

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Member

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)?

@sinhrks sinhrks added Bug Frequency DateOffsets labels Oct 20, 2016
@sinhrks sinhrks added this to the 0.19.1 milestone Oct 20, 2016
@codecov-io
Copy link

codecov-io commented Oct 20, 2016

Codecov Report

Merging #14458 into master will decrease coverage by -0.03%.
The diff coverage is 100%.

@@            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
Impacted Files Coverage Δ
pandas/tseries/resample.py 94.5% <100%> (+0.02%)
pandas/io/gbq.py 25% <0%> (-58.34%)
pandas/tools/merge.py 91.78% <0%> (-0.35%)
pandas/util/testing.py 81.87% <0%> (-0.19%)
pandas/core/frame.py 97.82% <0%> (-0.1%)
pandas/core/common.py 91.36% <0%> (+0.33%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 211ecd5...384e666. Read the comment docs.

@sahildua2305 sahildua2305 force-pushed the frequency-series-fix branch 2 times, most recently from 0bb68de to 6d95b3a Compare October 28, 2016 15:18
is not scalar and ``values`` is not specified (:issue:`14380`)
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
Copy link
Member

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

Copy link
Contributor

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

Copy link
Contributor Author

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')
Copy link
Member

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)

Copy link
Contributor Author

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.

@jorisvandenbossche jorisvandenbossche modified the milestones: 0.20.0, 0.19.1 Nov 1, 2016
@jorisvandenbossche
Copy link
Member

@sahildua2305 Can you update?

@sahildua2305
Copy link
Contributor Author

Got busy with stuff. I will update this soon @jorisvandenbossche

@jreback
Copy link
Contributor

jreback commented Dec 16, 2016

can you rebase / update

@sahildua2305
Copy link
Contributor Author

Yes, will do!

result = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]),
data=[3]).asfreq('H')
self.assert_index_equal(expected.index, result.index)

Copy link
Contributor

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

@@ -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'],
Copy link
Contributor

Choose a reason for hiding this comment

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

same here as above

@jreback
Copy link
Contributor

jreback commented Dec 30, 2016

can you rebase / update

@jreback
Copy link
Contributor

jreback commented Feb 27, 2017

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
@sahildua2305 sahildua2305 force-pushed the frequency-series-fix branch from 1494d85 to 384e666 Compare March 2, 2017 23:55
@jreback jreback closed this in 0b07b07 Mar 3, 2017
@jreback
Copy link
Contributor

jreback commented Mar 3, 2017

thanks!

@sahildua2305 sahildua2305 deleted the frequency-series-fix branch March 3, 2017 13:17
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Frequency not set for empty Series
5 participants