From 2e77cef7dadd9607871f486371bb395751e293f3 Mon Sep 17 00:00:00 2001 From: VirosaLi Date: Mon, 8 Jun 2020 10:08:49 -0500 Subject: [PATCH 01/19] TST: groupby apply with indexing and colunm aggregation returns the column (#7002) --- pandas/tests/groupby/test_apply.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index bc8067212d60e..ec454f1b3e93f 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -961,3 +961,13 @@ def fn(x): name="col2", ) tm.assert_series_equal(result, expected) + + +def test_apply_function_with_indexing_return_column(): + # GH: 7002 + df = DataFrame({'foo1': ['one', 'two', 'two', 'three', 'one', 'two'], + 'foo2': np.random.randn(6)}) + result = df.groupby('foo1', as_index=False).apply(lambda x: x.mean()) + expected = df.groupby('foo1', as_index=False).mean() + tm.assert_frame_equal(result, expected) + assert 'foo1' in result.columns From ce4db3c1b7c168a2062580fedfeb7f4e5db22050 Mon Sep 17 00:00:00 2001 From: VirosaLi Date: Sun, 14 Jun 2020 14:16:15 -0500 Subject: [PATCH 02/19] Revert "TST: groupby apply with indexing and colunm aggregation returns the column (#7002)" This reverts commit 2e77cef7dadd9607871f486371bb395751e293f3. --- pandas/tests/groupby/test_apply.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index ec454f1b3e93f..bc8067212d60e 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -961,13 +961,3 @@ def fn(x): name="col2", ) tm.assert_series_equal(result, expected) - - -def test_apply_function_with_indexing_return_column(): - # GH: 7002 - df = DataFrame({'foo1': ['one', 'two', 'two', 'three', 'one', 'two'], - 'foo2': np.random.randn(6)}) - result = df.groupby('foo1', as_index=False).apply(lambda x: x.mean()) - expected = df.groupby('foo1', as_index=False).mean() - tm.assert_frame_equal(result, expected) - assert 'foo1' in result.columns From 31b5d8f76fa30ff5aa44eff57a31d68b89a9b3b9 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 30 Jun 2020 13:01:41 -0500 Subject: [PATCH 03/19] ENH: add index option for SQL git_schema --- pandas/io/sql.py | 17 +++++++++++------ pandas/tests/io/test_sql.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index b137608475b3d..de752d97ed0d6 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1441,9 +1441,9 @@ def drop_table(self, table_name, schema=None): self.get_table(table_name, schema).drop() self.meta.clear() - def _create_sql_schema(self, frame, table_name, keys=None, dtype=None): + def _create_sql_schema(self, frame, table_name, keys=None, dtype=None, index=False): table = SQLTable( - table_name, self, frame=frame, index=False, keys=keys, dtype=dtype + table_name, self, frame=frame, index=index, keys=keys, dtype=dtype ) return str(table.sql_schema()) @@ -1831,14 +1831,14 @@ def drop_table(self, name, schema=None): drop_sql = f"DROP TABLE {_get_valid_sqlite_name(name)}" self.execute(drop_sql) - def _create_sql_schema(self, frame, table_name, keys=None, dtype=None): + def _create_sql_schema(self, frame, table_name, keys=None, dtype=None, index=False): table = SQLiteTable( - table_name, self, frame=frame, index=False, keys=keys, dtype=dtype + table_name, self, frame=frame, index=index, keys=keys, dtype=dtype ) return str(table.sql_schema()) -def get_schema(frame, name, keys=None, con=None, dtype=None): +def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): """ Get the SQL db table schema for the given frame. @@ -1856,7 +1856,12 @@ 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 the index of the DataFrame in the sql schema + New in version 1.1.0. """ pandas_sql = pandasSQL_builder(con=con) - return pandas_sql._create_sql_schema(frame, name, keys=keys, dtype=dtype) + return pandas_sql._create_sql_schema( + frame, name, keys=keys, dtype=dtype, index=index + ) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index a07e7a74b7573..f4bf37040c582 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -887,6 +887,20 @@ def test_get_schema_keys(self): constraint_sentence = 'CONSTRAINT test_pk PRIMARY KEY ("A", "B")' assert constraint_sentence in create_sql + def test_get_schema_with_index(self): + # GH 9084 + df = pd.DataFrame({"one": [1, 2, 3], "two": [1, 2, 3]}, index=list("abc")) + + schema_without_index = sql.get_schema(df, "test", con=self.conn) + assert "index TEXT" not in schema_without_index + + schema_with_index = sql.get_schema(df, "test", index=True, con=self.conn) + assert '"index" TEXT' in schema_with_index + + df.index.name = "new_index" + schema_with_index_rename = sql.get_schema(df, "test", index=True, con=self.conn) + assert df.index.name in schema_with_index_rename + def test_chunksize_read(self): df = DataFrame(np.random.randn(22, 5), columns=list("abcde")) df.to_sql("test_chunksize", self.conn, index=False) From a9faad0f9403e5b84479577b7d0c8908b2d3b33d Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 2 Jul 2020 11:48:25 -0500 Subject: [PATCH 04/19] add whatsnew 1.1.0 entry --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 9bd4ddbb624d9..d9f489e356b47 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -329,6 +329,7 @@ Other enhancements - :meth:`DataFrame.to_excel` can now also write OpenOffice spreadsheet (.ods) files (:issue:`27222`) - :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`). - :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`) +- :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). .. --------------------------------------------------------------------------- From d0779950da3f6e88a023e7e618665a2a9d101bfd Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 10:47:52 -0500 Subject: [PATCH 05/19] fix doc --- doc/source/reference/io.rst | 7 +++++++ doc/source/whatsnew/v1.1.0.rst | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/source/reference/io.rst b/doc/source/reference/io.rst index 0037d4a4410c3..c9505721ae172 100644 --- a/doc/source/reference/io.rst +++ b/doc/source/reference/io.rst @@ -127,6 +127,13 @@ SQL read_sql_query read_sql +.. currentmodule:: pandas.io.sql + +.. autosummary:: + :toctree: api/ + + get_schema + Google BigQuery ~~~~~~~~~~~~~~~ .. autosummary:: diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index d9f489e356b47..9bd4ddbb624d9 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -329,7 +329,6 @@ Other enhancements - :meth:`DataFrame.to_excel` can now also write OpenOffice spreadsheet (.ods) files (:issue:`27222`) - :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`). - :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`) -- :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). .. --------------------------------------------------------------------------- From c96ba29930030064afbc1f58fbda4ff07013cdac Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 11:03:27 -0500 Subject: [PATCH 06/19] fix doc --- doc/source/reference/io.rst | 8 +------- doc/source/whatsnew/v1.1.0.rst | 1 + pandas/io/sql.py | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/doc/source/reference/io.rst b/doc/source/reference/io.rst index c9505721ae172..075e57eb39106 100644 --- a/doc/source/reference/io.rst +++ b/doc/source/reference/io.rst @@ -126,13 +126,7 @@ SQL read_sql_table read_sql_query read_sql - -.. currentmodule:: pandas.io.sql - -.. autosummary:: - :toctree: api/ - - get_schema + sql.get_schema Google BigQuery ~~~~~~~~~~~~~~~ diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 9bd4ddbb624d9..d9f489e356b47 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -329,6 +329,7 @@ Other enhancements - :meth:`DataFrame.to_excel` can now also write OpenOffice spreadsheet (.ods) files (:issue:`27222`) - :meth:`~Series.explode` now accepts ``ignore_index`` to reset the index, similarly to :meth:`pd.concat` or :meth:`DataFrame.sort_values` (:issue:`34932`). - :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`) +- :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). .. --------------------------------------------------------------------------- diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 335df16ce346b..3745afd2e7eb6 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1871,7 +1871,8 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): be a SQLAlchemy type, or a string for sqlite3 fallback connection. index : boolean, default: False Whether to include the index of the DataFrame in the sql schema - New in version 1.1.0. + + .. versionadded:: 1.1.0 """ pandas_sql = pandasSQL_builder(con=con) From 430eaf7574edf43fa1ac3806a45b0e692297a514 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 11:30:31 -0500 Subject: [PATCH 07/19] fix doc --- doc/source/reference/io.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/reference/io.rst b/doc/source/reference/io.rst index 075e57eb39106..9502d319075ce 100644 --- a/doc/source/reference/io.rst +++ b/doc/source/reference/io.rst @@ -126,7 +126,7 @@ SQL read_sql_table read_sql_query read_sql - sql.get_schema + io.sql.get_schema Google BigQuery ~~~~~~~~~~~~~~~ From 7d1886d9c0fcb1aadeed139345293cde9e8d8933 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 12:13:16 -0500 Subject: [PATCH 08/19] fix docstring --- pandas/io/sql.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 3745afd2e7eb6..53a4984ade11d 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1862,7 +1862,7 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): name of SQL table keys : string or sequence, default: None columns to use a primary key - con: an open SQL database connection object or a SQLAlchemy connectable + con : an open SQL database connection object or a SQLAlchemy connectable Using SQLAlchemy makes it possible to use any DB supported by that library, default: None If a DBAPI2 object, only sqlite3 is supported. @@ -1870,10 +1870,14 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): 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 the index of the DataFrame in the sql schema + Whether to include the index of the DataFrame in the sql schema. .. versionadded:: 1.1.0 + Returns + ------- + string + the SQL schema for the given frame """ pandas_sql = pandasSQL_builder(con=con) return pandas_sql._create_sql_schema( From 089af78ec2e2f862ffdb14ae3288ced8017054cd Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 13:00:45 -0500 Subject: [PATCH 09/19] fix docstring --- pandas/io/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 53a4984ade11d..7de3fef8ff73c 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1877,7 +1877,7 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): Returns ------- string - the SQL schema for the given frame + The SQL schema for the given frame. """ pandas_sql = pandasSQL_builder(con=con) return pandas_sql._create_sql_schema( From 4134dc7698fe4ad383dbd57c5ec386d384ebb90a Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 6 Jul 2020 23:40:07 -0500 Subject: [PATCH 10/19] whatsnew --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index c89f5f6ea6538..3380fd456099b 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -331,6 +331,7 @@ Other enhancements - :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`) - :class:`pandas.core.window.ExponentialMovingWindow` now supports a ``times`` argument that allows ``mean`` to be calculated with observations spaced by the timestamps in ``times`` (:issue:`34839`) - :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). +.. --------------------------------------------------------------------------- .. _whatsnew_110.api: From 938eca75c199f120d72e99ee4b182ad690c25312 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Thu, 9 Jul 2020 19:41:11 -0500 Subject: [PATCH 11/19] fix doc --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 04ac300cf71ed..01c49b15f7735 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -332,6 +332,7 @@ Other enhancements - :meth:`read_csv` now accepts string values like "0", "0.0", "1", "1.0" as convertible to the nullable boolean dtype (:issue:`34859`) - :class:`pandas.core.window.ExponentialMovingWindow` now supports a ``times`` argument that allows ``mean`` to be calculated with observations spaced by the timestamps in ``times`` (:issue:`34839`) - :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). + .. --------------------------------------------------------------------------- .. _whatsnew_110.api: From 05512c44a9383a22ea26e3b1f9f6dd3b0407b802 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 16 Sep 2020 13:47:25 -0500 Subject: [PATCH 12/19] update doc --- doc/source/whatsnew/v1.2.0.rst | 1 + pandas/io/sql.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 3992e697db7e4..5c29fa7c5b703 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -316,6 +316,7 @@ I/O - :meth:`to_csv` did not support zip compression for binary file object not having a filename (:issue:`35058`) - :meth:`to_csv` and :meth:`read_csv` did not honor `compression` and `encoding` for path-like objects that are internally converted to file-like objects (:issue:`35677`, :issue:`26124`, and :issue:`32392`) - :meth:`to_picke` and :meth:`read_pickle` did not support compression for file-objects (:issue:`26237`, :issue:`29054`, and :issue:`29570`) +- :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). Plotting ^^^^^^^^ diff --git a/pandas/io/sql.py b/pandas/io/sql.py index fb395fee65307..be0d394a26bd9 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1873,7 +1873,7 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, index=False): index : boolean, default: False Whether to include the index of the DataFrame in the sql schema. - .. versionadded:: 1.1.0 + .. versionadded:: 1.2.0 Returns ------- From 57e83fe912b416c43e48e06d76a5ab67d41452b7 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 26 Sep 2020 13:05:51 -0500 Subject: [PATCH 13/19] fix doc --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 7f3114fb94f3c..99ccb921572b4 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -328,7 +328,7 @@ I/O - Bug in :func:`LongTableBuilder.middle_separator` was duplicating LaTeX longtable entries in the List of Tables of a LaTeX document (:issue:`34360`) - Bug in :meth:`read_csv` with ``engine='python'`` truncating data if multiple items present in first row and first element started with BOM (:issue:`36343`) - Removed ``private_key`` and ``verbose`` from :func:`read_gbq` as they are no longer supported in ``pandas-gbq`` (:issue:`34654`, :issue:`30200`) -- :meth:`~pandas.io.sql.get_schema` now accepts `index` parameter to include index of the DataFrame in the schema (:issue:`9084`). +- :meth:``~pandas.io.sql.get_schema`` now accepts ``index`` parameter to include index of the DataFrame in the schema (:issue:`9084`). Plotting ^^^^^^^^ From 7a9e8fc2952036c3d692a4cc9761f8891d5e15ee Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sat, 26 Sep 2020 13:18:45 -0500 Subject: [PATCH 14/19] Update doc/source/whatsnew/v1.2.0.rst Co-authored-by: Daniel Saxton <2658661+dsaxton@users.noreply.github.com> --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 99ccb921572b4..758840a68e59f 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -328,7 +328,7 @@ I/O - Bug in :func:`LongTableBuilder.middle_separator` was duplicating LaTeX longtable entries in the List of Tables of a LaTeX document (:issue:`34360`) - Bug in :meth:`read_csv` with ``engine='python'`` truncating data if multiple items present in first row and first element started with BOM (:issue:`36343`) - Removed ``private_key`` and ``verbose`` from :func:`read_gbq` as they are no longer supported in ``pandas-gbq`` (:issue:`34654`, :issue:`30200`) -- :meth:``~pandas.io.sql.get_schema`` now accepts ``index`` parameter to include index of the DataFrame in the schema (:issue:`9084`). +- :meth:`~pandas.io.sql.get_schema` now accepts ``index`` parameter to include index of the DataFrame in the schema (:issue:`9084`). Plotting ^^^^^^^^ From 70c2101273bd15987851cf817d542a90c604e320 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 7 Dec 2020 21:29:14 -0600 Subject: [PATCH 15/19] fix long line --- pandas/io/sql.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index cbf6e588994b4..01b01a5d044b9 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1862,7 +1862,15 @@ def drop_table(self, name, schema=None): drop_sql = f"DROP TABLE {_get_valid_sqlite_name(name)}" self.execute(drop_sql) - def _create_sql_schema(self, frame, table_name, keys=None, dtype=None, schema=None, index=False): + def _create_sql_schema( + self, + frame, + table_name, + keys=None, + dtype=None, + schema=None, + index=False, + ): table = SQLiteTable( table_name, self, From 47c2315d09e43e9c95fccec5983356dbb8ad72ad Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 7 Dec 2020 21:37:23 -0600 Subject: [PATCH 16/19] Update sql.py --- pandas/io/sql.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 01b01a5d044b9..36c7d4458bc55 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1863,12 +1863,12 @@ def drop_table(self, name, schema=None): self.execute(drop_sql) def _create_sql_schema( - self, - frame, - table_name, - keys=None, - dtype=None, - schema=None, + self, + frame, + table_name, + keys=None, + dtype=None, + schema=None, index=False, ): table = SQLiteTable( From 5b152b03aa591a84923ddd54cf5ca3132128d7eb Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 7 Dec 2020 21:45:07 -0600 Subject: [PATCH 17/19] remove pd usage --- pandas/tests/io/test_sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 52cc5fcc5b2e2..86b1f7a2bea3c 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -896,7 +896,7 @@ def test_get_schema_keys(self): def test_get_schema_with_index(self): # GH 9084 - df = pd.DataFrame({"one": [1, 2, 3], "two": [1, 2, 3]}, index=list("abc")) + df = DataFrame({"one": [1, 2, 3], "two": [1, 2, 3]}, index=list("abc")) schema_without_index = sql.get_schema(df, "test", con=self.conn) assert "index TEXT" not in schema_without_index From 23f14c42a6a48c715736fd1c36e4ddbee65ab024 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 7 Dec 2020 22:12:39 -0600 Subject: [PATCH 18/19] Update sql.py --- pandas/io/sql.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 36c7d4458bc55..21b26275378e3 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1462,6 +1462,7 @@ def _create_sql_schema( keys: Optional[List[str]] = None, dtype: Optional[dict] = None, schema: Optional[str] = None, + index: Optional[bool] = False, ): table = SQLTable( table_name, From 0dd76d1fdbafead8447479ffda82b8228ca076bd Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 7 Dec 2020 22:45:56 -0600 Subject: [PATCH 19/19] fix docstring --- pandas/io/sql.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 21b26275378e3..c766c04224cec 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1902,14 +1902,14 @@ def get_schema(frame, name, keys=None, con=None, dtype=None, schema=None, index= 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. - schema: str, default: None + schema : str, default: None Optional specifying the schema to be used in creating the table. .. versionadded:: 1.2.0 index : boolean, default: False - Whether to include the index of the DataFrame in the sql schema. + Whether to include the index of the DataFrame in the sql schema. - .. versionadded:: 1.2.0 + .. versionadded:: 1.2.0 Returns -------