Skip to content
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

ENH: Support index=True for io.sql.get_schema #25030

Closed

Conversation

vrajmohan
Copy link

@vrajmohan vrajmohan commented Jan 30, 2019

Closes #9084

  • Decided to keep the default as index=False to keep the API consistent. to_sql has index=True.

  • Tempted to name the parameter include_dataframe_index as "index" has
    a different meaning in a SQL context.

  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

  • whatsnew entry

@codecov
Copy link

codecov bot commented Jan 30, 2019

Codecov Report

Merging #25030 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #25030   +/-   ##
=======================================
  Coverage   92.38%   92.38%           
=======================================
  Files         166      166           
  Lines       52401    52401           
=======================================
  Hits        48409    48409           
  Misses       3992     3992
Flag Coverage Δ
#multiple 90.8% <ø> (ø) ⬆️
#single 42.88% <ø> (ø) ⬆️

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 b9f2e2b...f702c78. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 30, 2019

Codecov Report

Merging #25030 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25030      +/-   ##
==========================================
- Coverage   92.37%   92.36%   -0.01%     
==========================================
  Files         166      166              
  Lines       52403    52403              
==========================================
- Hits        48405    48404       -1     
- Misses       3998     3999       +1
Flag Coverage Δ
#multiple 90.79% <ø> (ø) ⬆️
#single 42.87% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/util/testing.py 88.04% <0%> (-0.1%) ⬇️

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 ea013a2...722dc56. Read the comment docs.

@gfyoung gfyoung added Enhancement IO SQL to_sql, read_sql, read_sql_query labels Jan 30, 2019
``get_schema`` Enhancements
^^^^^^^^^^^^^^^^^^^^^^^^^^

:func:`get_schema` now accepts an `index` parameter (default: `False`) that includes the index in the generated schema. (:issue:`9084`)
Copy link
Member

Choose a reason for hiding this comment

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

Move this to the 0.25.0 whatsnew.

Copy link
Member

Choose a reason for hiding this comment

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

I would also just add it as a bullet point under the I/O section of the document.

pandas/io/sql.py Outdated
@@ -1588,8 +1590,11 @@ def get_schema(frame, name, keys=None, con=None, dtype=None):
dtype : dict of column name to SQL type, default None
Optional specifying the datatype for columns. The SQL type should
be a SQLAlchemy type, or a string for sqlite3 fallback connection.
index : boolean, default False
include DataFrame index as a column
Copy link
Member

Choose a reason for hiding this comment

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

"include..." --> "Whether to include..."

Vraj Mohan added 6 commits January 31, 2019 16:16
Closes pandas-dev#9084

- Decided to keep the default as `index=False` to keep the API consistent. `to_sql` has `index=True`.
- Tempted to name the parameter `include_dataframe_index` as "index" has
a different meaning in a SQL context.
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Can you merge master?

@@ -1589,8 +1591,11 @@ def get_schema(frame, name, keys=None, con=None, dtype=None):
dtype : dict of column name to SQL type, default None
Optional specifying the datatype for columns. The SQL type should
be a SQLAlchemy type, or a string for sqlite3 fallback connection.
index : boolean, default False
Whether to include DataFrame index as a column
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 add a period here at the end of the description?

@@ -31,7 +31,6 @@ Fixed Regressions
Enhancements
^^^^^^^^^^^^


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 revert changes to this file?

@@ -823,6 +823,21 @@ def test_get_schema_keys(self):
constraint_sentence = 'CONSTRAINT test_pk PRIMARY KEY ("A", "B")'
assert constraint_sentence in create_sql

@pytest.mark.parametrize("index_arg, expected", [
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better if you simply parametrized on True and False and made "expected" the actual expected statement

({"index": True}, True),
])
def test_get_schema_with_index(self, index_arg, expected):
frame = DataFrame({
Copy link
Member

Choose a reason for hiding this comment

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

Call this df instead of frame

@WillAyd
Copy link
Member

WillAyd commented May 3, 2019

I think this has gone stale but please ping if you'd like to continue!

@WillAyd WillAyd closed this May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO SQL to_sql, read_sql, read_sql_query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: support index=True for SQL io.sql.get_schema
3 participants