Skip to content

Commit 3aeba22

Browse files
authored
Merge branch 'main' into coercion
2 parents ec144ff + 79b131e commit 3aeba22

File tree

12 files changed

+32
-91
lines changed

12 files changed

+32
-91
lines changed

.github/workflows/scorecards.yml

-55
This file was deleted.

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
[![Package Status](https://img.shields.io/pypi/status/pandas.svg)](https://pypi.org/project/pandas/)
1212
[![License](https://img.shields.io/pypi/l/pandas.svg)](https://github.com/pandas-dev/pandas/blob/main/LICENSE)
1313
[![Coverage](https://codecov.io/github/pandas-dev/pandas/coverage.svg?branch=main)](https://codecov.io/gh/pandas-dev/pandas)
14-
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/pandas-dev/pandas/badge)](https://api.securityscorecards.dev/projects/github.com/pandas-dev/pandas)
1514
[![Downloads](https://static.pepy.tech/personalized-badge/pandas?period=month&units=international_system&left_color=black&right_color=orange&left_text=PyPI%20downloads%20per%20month)](https://pepy.tech/project/pandas)
1615
[![Slack](https://img.shields.io/badge/join_Slack-information-brightgreen.svg?logo=slack)](https://pandas.pydata.org/docs/dev/development/community.html?highlight=slack#community-slack)
1716
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)

doc/source/getting_started/comparison/comparison_with_sas.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The pandas method is :func:`read_csv`, which works similarly.
112112
.. ipython:: python
113113
114114
url = (
115-
"https://raw.github.com/pandas-dev/"
115+
"https://raw.githubusercontent.com/pandas-dev/"
116116
"pandas/main/pandas/tests/io/data/csv/tips.csv"
117117
)
118118
tips = pd.read_csv(url)

doc/source/getting_started/comparison/comparison_with_spreadsheets.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ In pandas, you pass the URL or local path of the CSV file to :func:`~pandas.read
100100
.. ipython:: python
101101
102102
url = (
103-
"https://raw.github.com/pandas-dev"
103+
"https://raw.githubusercontent.com/pandas-dev"
104104
"/pandas/main/pandas/tests/io/data/csv/tips.csv"
105105
)
106106
tips = pd.read_csv(url)

doc/source/getting_started/comparison/comparison_with_sql.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ structure.
1717
.. ipython:: python
1818
1919
url = (
20-
"https://raw.github.com/pandas-dev"
20+
"https://raw.githubusercontent.com/pandas-dev"
2121
"/pandas/main/pandas/tests/io/data/csv/tips.csv"
2222
)
2323
tips = pd.read_csv(url)

doc/source/getting_started/comparison/comparison_with_stata.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ the data set if presented with a url.
108108
.. ipython:: python
109109
110110
url = (
111-
"https://raw.github.com/pandas-dev"
111+
"https://raw.githubusercontent.com/pandas-dev"
112112
"/pandas/main/pandas/tests/io/data/csv/tips.csv"
113113
)
114114
tips = pd.read_csv(url)

doc/source/user_guide/io.rst

-15
Original file line numberDiff line numberDiff line change
@@ -5790,21 +5790,6 @@ Specifying this will return an iterator through chunks of the query result:
57905790
for chunk in pd.read_sql_query("SELECT * FROM data_chunks", engine, chunksize=5):
57915791
print(chunk)
57925792
5793-
You can also run a plain query without creating a ``DataFrame`` with
5794-
:func:`~pandas.io.sql.execute`. This is useful for queries that don't return values,
5795-
such as INSERT. This is functionally equivalent to calling ``execute`` on the
5796-
SQLAlchemy engine or db connection object. Again, you must use the SQL syntax
5797-
variant appropriate for your database.
5798-
5799-
.. code-block:: python
5800-
5801-
from pandas.io import sql
5802-
5803-
sql.execute("SELECT * FROM table_name", engine)
5804-
sql.execute(
5805-
"INSERT INTO table_name VALUES(?, ?, ?)", engine, params=[("id", 1, 12.2, True)]
5806-
)
5807-
58085793
58095794
Engine connection examples
58105795
''''''''''''''''''''''''''

pandas/io/sql.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ def execute(sql, con, params=None):
192192
----------
193193
sql : string
194194
SQL query to be executed.
195-
con : SQLAlchemy connectable(engine/connection) or sqlite3 connection
196-
Using SQLAlchemy makes it possible to use any DB supported by the
197-
library.
195+
con : SQLAlchemy connection or sqlite3 connection
198196
If a DBAPI2 object, only sqlite3 is supported.
199197
params : list or tuple, optional, default: None
200198
List of parameters to pass to execute method.
@@ -203,6 +201,10 @@ def execute(sql, con, params=None):
203201
-------
204202
Results Iterable
205203
"""
204+
sqlalchemy = import_optional_dependency("sqlalchemy", errors="ignore")
205+
206+
if sqlalchemy is not None and isinstance(con, (str, sqlalchemy.engine.Engine)):
207+
raise TypeError("pandas.io.sql.execute requires a connection") # GH50185
206208
with pandasSQL_builder(con, need_transaction=True) as pandas_sql:
207209
args = _convert_params(sql, params)
208210
return pandas_sql.execute(*args)

pandas/plotting/_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def andrews_curves(
311311
:context: close-figs
312312
313313
>>> df = pd.read_csv(
314-
... 'https://raw.github.com/pandas-dev/'
314+
... 'https://raw.githubusercontent.com/pandas-dev/'
315315
... 'pandas/main/pandas/tests/io/data/csv/iris.csv'
316316
... )
317317
>>> pd.plotting.andrews_curves(df, 'Name')
@@ -443,7 +443,7 @@ def parallel_coordinates(
443443
:context: close-figs
444444
445445
>>> df = pd.read_csv(
446-
... 'https://raw.github.com/pandas-dev/'
446+
... 'https://raw.githubusercontent.com/pandas-dev/'
447447
... 'pandas/main/pandas/tests/io/data/csv/iris.csv'
448448
... )
449449
>>> pd.plotting.parallel_coordinates(

pandas/tests/io/parser/common/test_file_buffer_url.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
@pytest.mark.network
3131
@tm.network(
3232
url=(
33-
"https://raw.github.com/pandas-dev/pandas/main/"
33+
"https://raw.githubusercontent.com/pandas-dev/pandas/main/"
3434
"pandas/tests/io/parser/data/salaries.csv"
3535
),
3636
check_before_test=True,
@@ -40,7 +40,7 @@ def test_url(all_parsers, csv_dir_path):
4040
kwargs = {"sep": "\t"}
4141

4242
url = (
43-
"https://raw.github.com/pandas-dev/pandas/main/"
43+
"https://raw.githubusercontent.com/pandas-dev/pandas/main/"
4444
"pandas/tests/io/parser/data/salaries.csv"
4545
)
4646
url_result = parser.read_csv(url, **kwargs)

pandas/tests/io/test_sql.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ def psql_insert_copy(table, conn, keys, data_iter):
663663
tm.assert_frame_equal(result, expected)
664664

665665

666+
def test_execute_typeerror(sqlite_iris_engine):
667+
with pytest.raises(TypeError, match="pandas.io.sql.execute requires a connection"):
668+
sql.execute("select * from iris", sqlite_iris_engine)
669+
670+
666671
class MixInBase:
667672
def teardown_method(self):
668673
# if setup fails, there may not be a connection to close.
@@ -956,7 +961,8 @@ def test_roundtrip_chunksize(self, test_frame1):
956961

957962
def test_execute_sql(self):
958963
# drop_sql = "DROP TABLE IF EXISTS test" # should already be done
959-
iris_results = sql.execute("SELECT * FROM iris", con=self.conn)
964+
with sql.pandasSQL_builder(self.conn) as pandas_sql:
965+
iris_results = pandas_sql.execute("SELECT * FROM iris")
960966
row = iris_results.fetchone()
961967
tm.equalContents(row, [5.1, 3.5, 1.4, 0.2, "Iris-setosa"])
962968

@@ -2795,7 +2801,8 @@ def format_query(sql, *args):
27952801

27962802
def tquery(query, con=None):
27972803
"""Replace removed sql.tquery function"""
2798-
res = sql.execute(query, con=con).fetchall()
2804+
with sql.pandasSQL_builder(con) as pandas_sql:
2805+
res = pandas_sql.execute(query).fetchall()
27992806
return None if res is None else list(res)
28002807

28012808

@@ -2860,7 +2867,8 @@ def test_execute(self, sqlite_buildin):
28602867
ins = "INSERT INTO test VALUES (?, ?, ?, ?)"
28612868

28622869
row = frame.iloc[0]
2863-
sql.execute(ins, sqlite_buildin, params=tuple(row))
2870+
with sql.pandasSQL_builder(sqlite_buildin) as pandas_sql:
2871+
pandas_sql.execute(ins, tuple(row))
28642872
sqlite_buildin.commit()
28652873

28662874
result = sql.read_sql("select * from test", sqlite_buildin)
@@ -2895,11 +2903,12 @@ def test_execute_fail(self, sqlite_buildin):
28952903
cur = sqlite_buildin.cursor()
28962904
cur.execute(create_sql)
28972905

2898-
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', sqlite_buildin)
2899-
sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)', sqlite_buildin)
2906+
with sql.pandasSQL_builder(sqlite_buildin) as pandas_sql:
2907+
pandas_sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)')
2908+
pandas_sql.execute('INSERT INTO test VALUES("foo", "baz", 2.567)')
29002909

2901-
with pytest.raises(sql.DatabaseError, match="Execution failed on sql"):
2902-
sql.execute('INSERT INTO test VALUES("foo", "bar", 7)', sqlite_buildin)
2910+
with pytest.raises(sql.DatabaseError, match="Execution failed on sql"):
2911+
pandas_sql.execute('INSERT INTO test VALUES("foo", "bar", 7)')
29032912

29042913
def test_execute_closed_connection(self):
29052914
create_sql = """
@@ -2915,7 +2924,8 @@ def test_execute_closed_connection(self):
29152924
cur = conn.cursor()
29162925
cur.execute(create_sql)
29172926

2918-
sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)', conn)
2927+
with sql.pandasSQL_builder(conn) as pandas_sql:
2928+
pandas_sql.execute('INSERT INTO test VALUES("foo", "bar", 1.234)')
29192929

29202930
msg = "Cannot operate on a closed database."
29212931
with pytest.raises(sqlite3.ProgrammingError, match=msg):

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ classifiers = [
4848

4949
[project.urls]
5050
homepage = 'https://pandas.pydata.org'
51-
documentation = 'https://pandas.pydata.org/pandas-docs/stable'
51+
documentation = 'https://pandas.pydata.org/docs/'
5252
repository = 'https://github.com/pandas-dev/pandas'
5353

5454
[project.entry-points."pandas_plotting_backends"]

0 commit comments

Comments
 (0)