-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: If Series is called with no arguments, let it have a RangeIndex (#16737) #16961
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
doc/source/whatsnew/v0.21.0.txt
Outdated
@@ -201,3 +201,4 @@ Categorical | |||
Other | |||
^^^^^ | |||
- Bug in :func:`eval` where the ``inplace`` parameter was being incorrectly handled (:issue:`16732`) | |||
- The ``Series`` constructor with no arguments would have an index like ``Index([], dtype='object')`` instead of ``RangeIndex(start=0, stop=0, step=1)`` |
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.
make a less verbose comment, like:
Series
constructor will default to construct a RangeIndex, rather than an Index
when constructed as empty.
@@ -158,6 +158,8 @@ def __init__(self, data=None, index=None, dtype=None, name=None, | |||
|
|||
if data is None: | |||
data = {} | |||
if index is None: |
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.
needs a 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.
Should I add the test code in the following test? Or somewhere else?
Is setting check_index_type=True
enough?
def test_constructor_empty(self):
empty = Series()
empty2 = Series([])
# the are Index() and RangeIndex() which don't compare type equal
# but are just .equals
assert_series_equal(empty, empty2, check_index_type=False)
empty = Series(index=lrange(10))
empty2 = Series(np.nan, index=lrange(10))
assert_series_equal(empty, empty2)
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 prob just need to remove the check_index_type=False
and then your change should work
can you rebase and respond to comments |
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.
I would prefer to see this go the other way, so that pd.Series([]).index and pd.Series().index are both an empty Index with object dtype. Then we'll have a consistent rule of "empty = object dtype"
I also think we should aim for consistency, I'll change the code accordingly so pd.Series([]).index and pd.Series().index evaluate to an empty Index. |
revisiting this, can you rebase and update and we can review |
Hmmm, I think I messed up the rebase. Uhm. What should I do? |
@alanbato we should be able to recover it from your local Ping one of us on gitter at https://gitter.im/pydata/pandas and we'll walk you through it. |
Your actual commit is still in this branch, so a |
114ced1
to
759dd8c
Compare
I think I did it! Thanks for your help @TomAugspurger @jorisvandenbossche. Also pinging @jreback in case he has something to say Cheers! 🐍 |
I think we agree on this one (so what @TomAugspurger proposed) |
closing as stale, if you want to work on this, pls ping. |
git diff upstream/master -u -- "*.py" | flake8 --diff
Before:
Now: