-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Allow setting a column with a scalar and no index (revert #16823) #17894
Labels
Milestone
Comments
This was referenced Oct 16, 2017
toobaz
changed the title
Allow setting a column with a scalar and no index should raise (revert #16823)
Allow setting a column with a scalar and no index (revert #16823)
Oct 16, 2017
jorisvandenbossche
added
API Design
Indexing
Related to indexing on series/frames, not to indexes themselves
labels
Oct 16, 2017
jreback
added a commit
to jreback/pandas
that referenced
this issue
Oct 17, 2017
yeemey
pushed a commit
to yeemey/pandas
that referenced
this issue
Oct 20, 2017
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
alanbato
pushed a commit
to alanbato/pandas
that referenced
this issue
Nov 10, 2017
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
No-Stream
pushed a commit
to No-Stream/pandas
that referenced
this issue
Nov 28, 2017
…h no index ( pandas-dev#16823) (pandas-dev#16968)" (pandas-dev#17902) * Revert "ERR: Raise ValueError when setting scalars in a dataframe with no index ( pandas-dev#16823) (pandas-dev#16968)" This reverts commit f9ba6fe. * TST: expicit test on setting scalars on empty frame closes pandas-dev#17894
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Extract of discussion from #16823
Code Sample, a copy-pastable example if possible
Problem description
Previously, the above would just add a new (obviously empty) column.
@jreback objects that if this is allowed, then we should also allow initialization with only scalars (as in
pd.Dataframe({'a' : 1, 'b' : 2})
I'm not 100% sure of what @jorisvandenbossche suggests, but he agrees with me that the current state is inconsistent.
My view is that previously things were just (almost) fine:
DataFrame
needs to have an index. You can avoid providing one expliclty only if it can be automatically built for the values you pass (i.e. 1-dimensional objects of the same length, or a single 2-dimensional block of data). Scalars clearly do not satisfy this requirement, so the constructor will raise if passed only scalars (butpd.DataFrame({'A' : range(3), 'B' : 23})
works, which is cool).In both cases, scalars/empty indexes represent no exception to the general behavior.
For consistency, we might want to fix the following too:
but I will detail this in a separate issue.
Expected Output
None, but a new column
"dummy"
is added todf
.Output of
pd.show_versions()
INSTALLED VERSIONS
commit: 5bf7f9a
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-3-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: it_IT.UTF-8
LOCALE: it_IT.UTF-8
pandas: 0.21.0rc1+18.g5bf7f9a4f
pytest: 3.0.6
pip: 9.0.1
setuptools: None
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
pyarrow: None
xarray: None
IPython: 5.1.0.dev
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.3.0
numexpr: 2.6.1
feather: 0.3.1
matplotlib: 2.0.0
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.6
lxml: None
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.2.1
The text was updated successfully, but these errors were encountered: