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

532 fixing behaviour with alias #599

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.7.9dev

* [Fix] Fixed Set method in Connection class to recognize same descriptor with different aliases (#532)
* [Fix] Added bottom-padding to the buttons in table explorer. Now they are not hidden by the scrollbar (#540)
* [Feature] Modified `histogram` command to support data with NULL values (#176)
* [Fix] `psutil` is no longer a dependency for JupySQL ([#541](https://github.com/ploomber/jupysql/issues/541))
Expand Down
10 changes: 6 additions & 4 deletions doc/api/magic-plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -152,10 +152,11 @@ generate histograms without explicitly removing NULL entries.
`%sqlplot` returns a `matplotlib.Axes` object.

```{code-cell} ipython3
ax = %sqlplot histogram --table penguins.csv --column body_mass_g
ax = %sqlplot histogram --table penguins.csv --column body_mass_g
ax.set_title("Body mass (grams)")
_ = ax.grid()
```

## `%sqlplot bar`

```{versionadded} 0.7.6
Expand Down Expand Up @@ -196,7 +197,7 @@ You can also pass the orientation using the `orient` argument.

```{code-cell} ipython3
%sqlplot bar --table add_col --column species cnt --with add_col --orient h
```
```

You can also show the number on top of the bar using the `S`/`show-numbers` argument.

Expand Down Expand Up @@ -237,11 +238,12 @@ group by species
```{code-cell} ipython3
%sqlplot pie --table add_col --column species cnt --with add_col
```

Here, `species` is the `labels` column and `cnt` is the `x` column.


You can also show the percentage on top of the pie using the `S`/`show-numbers` argument.

```{code-cell} ipython3
%sqlplot pie --table penguins.csv --column species -S
```
```
7 changes: 4 additions & 3 deletions doc/api/magic-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -136,8 +136,8 @@ Or pass an alias (**added in 0.5.2**):
%sql --close db-two
```


## Specify creator function

```{code-cell} ipython3
import os
import sqlite3
Expand All @@ -146,6 +146,8 @@ import sqlite3
os.environ["DATABASE_URL"] = "sqlite:///"

# Define a function that returns a DBAPI connection


def creator():
return sqlite3.connect("")
```
Expand All @@ -154,7 +156,6 @@ def creator():
%sql --creator creator
```


## Create table

```{code-cell} ipython3
Expand Down
9 changes: 6 additions & 3 deletions doc/howto/ggplot-interact.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jupytext:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.14.5
jupytext_version: 1.14.6
kernelspec:
display_name: Python 3 (ipykernel)
language: python
Expand Down Expand Up @@ -193,8 +193,11 @@ show_legend = widgets.ToggleButton(

```{code-cell} ipython3
def plot(b, cmap, show_legend):
(ggplot("diamonds", aes(x="price")) + geom_histogram(bins=b, fill="cut", cmap=cmap)
+ facet_wrap("color", legend=show_legend))
(
ggplot("diamonds", aes(x="price"))
+ geom_histogram(bins=b, fill="cut", cmap=cmap)
+ facet_wrap("color", legend=show_legend)
)
```

```{code-cell} ipython3
Expand Down
21 changes: 15 additions & 6 deletions src/sql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,21 @@ def set(cls, descriptor, displaycon, connect_args=None, creator=None, alias=None
# is that we're missing some unit tests
# when descriptor is a connection object
# http://docs.sqlalchemy.org/en/rel_0_9/core/engines.html#custom-dbapi-connect-arguments # noqa
cls.current = existing or Connection.from_connect_str(
connect_str=descriptor,
connect_args=connect_args,
creator=creator,
alias=alias,
)
# allows to distinguish between same descriptor with different alias
if existing and existing.alias != alias:
cls.current = Connection.from_connect_str(
connect_str=descriptor,
connect_args=connect_args,
creator=creator,
alias=alias,
)
else:
cls.current = existing or Connection.from_connect_str(
connect_str=descriptor,
connect_args=connect_args,
creator=creator,
alias=alias,
)

else:
if cls.connections:
Expand Down