8000 BUG: Check for size != 0 before trying to insert #10193 by rekcahpassyla · Pull Request #10194 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Check for size != 0 before trying to insert #10193 #10194

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
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
BUG: Check for size != 0 before trying to insert #10193
  • Loading branch information
rekcahpassyla committed May 22, 2015
commit bf456034ef8b0f5859e2892d27e0c9ca052d69cd
10 changes: 10 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,16 @@ def test_setitem(self):
expected = self.series.append(Series([1],index=['foobar']))
assert_series_equal(s,expected)

# Test for issue #10193
series = pd.TimeSeries()
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use TimeSeries, just Series

series[pd.datetime(2012, 1, 1)] = 47
expected = pd.TimeSeries(47, [pd.datetime(2012, 1, 1)])
Copy link
Contributor

Choose a reason for hiding this comment

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

just use datetime

assert_series_equal(series, expected)

series = pd.TimeSeries(0, pd.date_range('2011-01-01', '2011-01-01'))[:0]
series[pd.datetime(2012, 1, 1)] = 47
assert_series_equal(series, expected)

def test_setitem_dtypes(self):

# change dtypes
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ def insert(self, loc, item):
if zone != izone:
raise ValueError('Passed item and index have different timezone')
# check freq can be preserved on edge cases
if self.freq is not None:
if self.size and self.freq is not None:
if (loc == 0 or loc == -len(self)) and item + self.freq == self[0]:
freq = self.freq
elif (loc == len(self)) and item - self.freq == self[-1]:
Expand Down
0