Skip to content

Commit d70b7b2

Browse files
authored
[Plot] Enhancements + Bug Fixes (#1301)
* [Plot] Enhancements + Bug Fixes - multiple corrections - it is now possible to draw plots without agg Should close: - * correction * Correcting the bug * Bug correction * correcting plotly pie
1 parent ea63f93 commit d70b7b2

File tree

17 files changed

+203
-74
lines changed

17 files changed

+203
-74
lines changed

verticapy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
__url__: str = "https://github.com/vertica/verticapy/"
3838
__license__: str = "Apache License, Version 2.0"
3939
__version__: str = "1.1.0-beta"
40-
__iteration__: int = 2
41-
__date__: str = "10032024"
42-
__last_commit__: str = "c4fa73aaaf54051fb35b325a5dd77573ba9b3f4c"
40+
__iteration__: int = 1
41+
__date__: str = "10042024"
42+
__last_commit__: str = "b229f82d26eb61ddfc0375a7169e27a33f60340a"
4343
__long_version__: str = f"{__version__}-{__iteration__}{__date__}-{__last_commit__}"
4444
__codecov__: float = 0.84
4545

verticapy/_typing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@
5858
PlottingObject = Union[
5959
"PlottingBase", "TableSample", "Axes", "mFigure", "Highchart", "Highstock", "Figure"
6060
]
61-
PlottingMethod = Union[Literal["density", "count", "avg", "min", "max", "sum"], str]
61+
PlottingMethod = Union[
62+
Literal[None, "density", "count", "avg", "min", "max", "sum"], str
63+
]
6264
ColorType = str

verticapy/core/vdataframe/_fill.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,8 @@ def fillna(
868868
| ``vDataFrame.``:py:meth:`~verticapy.vDataFrame.interpolate` : Fill missing values by interpolating.
869869
| ``vDataColumn.``:py:meth:`~verticapy.vDataColumn.fill_outliers` : Fill the outliers using the input method.
870870
"""
871-
method = method.lower()
871+
if isinstance(method, str):
872+
method = method.lower()
872873
by, order_by = format_type(by, order_by, dtype=list)
873874
by, order_by = self._parent.format_colnames(by, order_by)
874875
if method == "auto":

verticapy/core/vdataframe/_plotting.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ def bar(
251251
q Quantile of the
252252
:py:class:`~vDataColumns` ``of``
253253
(ex: 50% to get the median).
254+
- None:
255+
No Aggregations. Parameter ``of``
256+
must not be empty, otherwise it
257+
is ignored.
254258
255259
It can also be a cutomized aggregation,
256260
for example: ``AVG(column1) + 5``
@@ -425,6 +429,14 @@ def bar(
425429
categoryorder=categoryorder,
426430
**style_kwargs,
427431
)
432+
elif len(columns) == 2 and isinstance(method, NoneType) and not (of):
433+
return self[columns[0]].bar(
434+
method=None,
435+
of=columns[1],
436+
max_cardinality=max_cardinality[0],
437+
categoryorder=categoryorder,
438+
**style_kwargs,
439+
)
428440
elif kind == "drilldown":
429441
vpy_plt, kwargs = self.get_plotting_lib(
430442
class_name="DrillDownBarChart",
@@ -529,6 +541,10 @@ def barh(
529541
q Quantile of the
530542
:py:class:`~vDataColumns` ``of``
531543
(ex: 50% to get the median).
544+
- None:
545+
No Aggregations. Parameter ``of``
546+
must not be empty, otherwise it
547+
is ignored.
532548
533549
It can also be a cutomized aggregation,
534550
for example: ``AVG(column1) + 5``
@@ -706,6 +722,14 @@ def barh(
706722
categoryorder=categoryorder,
707723
**style_kwargs,
708724
)
725+
elif len(columns) == 2 and isinstance(method, NoneType) and not (of):
726+
return self[columns[0]].barh(
727+
method=None,
728+
of=columns[1],
729+
max_cardinality=max_cardinality[0],
730+
categoryorder=categoryorder,
731+
**style_kwargs,
732+
)
709733
elif kind == "drilldown":
710734
vpy_plt, kwargs = self.get_plotting_lib(
711735
class_name="DrillDownHorizontalBarChart",
@@ -2163,6 +2187,11 @@ def hexbin(
21632187
q Quantile of the
21642188
:py:class:`~vDataColumns` ``of``
21652189
(ex: 50% to get the median).
2190+
- None:
2191+
No Aggregations. Parameter ``of``
2192+
must not be empty, otherwise it
2193+
is ignored. The function to draw
2194+
the final chart will be ``max```.
21662195
21672196
of: str, optional
21682197
The vDataColumn used to compute the aggregation.
@@ -2221,7 +2250,7 @@ def hexbin(
22212250
}
22222251
)
22232252
2224-
Below is an examples of one type of hexbin plots:
2253+
Below is an example of one type of hexbin plots:
22252254
22262255
- Hexbin
22272256
@@ -2805,9 +2834,9 @@ def numh(
28052834
fd = max(
28062835
2.0 * (vDataColumn_075 - vDataColumn_025) / (count) ** (1.0 / 3.0), 1e-99
28072836
)
2808-
if method.lower() == "sturges":
2837+
if str(method).lower() == "sturges":
28092838
best_h = sturges
2810-
elif method.lower() in ("freedman_diaconis", "fd"):
2839+
elif str(method).lower() in ("freedman_diaconis", "fd"):
28112840
best_h = fd
28122841
else:
28132842
best_h = max(sturges, fd)
@@ -3001,6 +3030,8 @@ def bar(
30013030
q Quantile of the
30023031
:py:class:`~vDataColumns` ``of``
30033032
(ex: 50% to get the median).
3033+
- None:
3034+
No Aggregations.
30043035
30053036
It can also be a cutomized aggregation
30063037
(ex: AVG(column1) + 5).
@@ -3122,7 +3153,7 @@ def bar(
31223153
@save_verticapy_logs
31233154
def barh(
31243155
self,
3125-
method: str = "density",
3156+
method: PlottingMethod = "density",
31263157
of: Optional[str] = None,
31273158
max_cardinality: int = 6,
31283159
nbins: int = 0,
@@ -3168,6 +3199,8 @@ def barh(
31683199
q Quantile of the
31693200
:py:class:`~vDataColumns` ``of``
31703201
(ex: 50% to get the median).
3202+
- None:
3203+
No Aggregations.
31713204
31723205
It can also be a cutomized aggregation
31733206
(ex: AVG(column1) + 5).
@@ -3289,7 +3322,7 @@ def barh(
32893322
@save_verticapy_logs
32903323
def pie(
32913324
self,
3292-
method: str = "density",
3325+
method: PlottingMethod = "density",
32933326
of: Optional[str] = None,
32943327
max_cardinality: int = 6,
32953328
h: PythonNumber = 0,
@@ -3333,6 +3366,8 @@ def pie(
33333366
q Quantile of the
33343367
:py:class:`~vDataColumns` ``of``
33353368
(ex: 50% to get the median).
3369+
- None:
3370+
No Aggregations.
33363371
33373372
It can also be a cutomized aggregation
33383373
(ex: ``AVG(column1) + 5``).
@@ -3452,7 +3487,7 @@ def pie(
34523487
def spider(
34533488
self,
34543489
by: Optional[str] = None,
3455-
method: str = "density",
3490+
method: PlottingMethod = "density",
34563491
of: Optional[str] = None,
34573492
max_cardinality: tuple[int, int] = (6, 6),
34583493
h: tuple[PythonNumber, PythonNumber] = (None, None),
@@ -3592,7 +3627,7 @@ def spider(
35923627
def hist(
35933628
self,
35943629
by: Optional[str] = None,
3595-
method: str = "density",
3630+
method: PlottingMethod = "density",
35963631
of: Optional[str] = None,
35973632
h: Optional[PythonNumber] = None,
35983633
h_by: PythonNumber = 0,
@@ -3935,7 +3970,7 @@ def density(
39353970
def candlestick(
39363971
self,
39373972
ts: str,
3938-
method: str = "sum",
3973+
method: PlottingMethod = "sum",
39393974
q: tuple[float, float] = (0.25, 0.75),
39403975
start_date: Optional[PythonScalar] = None,
39413976
end_date: Optional[PythonScalar] = None,
@@ -4020,6 +4055,12 @@ def candlestick(
40204055
40214056
import numpy as np
40224057
4058+
We can create a variable ``N`` to fix the size:
4059+
4060+
.. ipython:: python
4061+
4062+
N = 30
4063+
40234064
Let's generate a dataset using the following data.
40244065
40254066
.. ipython:: python
@@ -4037,7 +4078,6 @@ def candlestick(
40374078
40384079
data["population"].candlestick(ts = "date")
40394080
4040-
40414081
.. ipython:: python
40424082
:suppress:
40434083
:okwarning:

verticapy/core/vdataframe/_sys.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def _get_catalog_value(
210210
return "VERTICAPY_NOT_PRECOMPUTED"
211211
return total
212212
elif method:
213-
method = verticapy_agg_name(method.lower())
213+
method = verticapy_agg_name(str(method).lower())
214214
if columns[1] in self[columns[0]]._catalog[method]:
215215
return self[columns[0]]._catalog[method][columns[1]]
216216
else:
@@ -1317,27 +1317,39 @@ def store_usage(self) -> int:
13171317
)
13181318
return store_usage
13191319

1320-
def rename(self, new_name: str) -> "vDataFrame":
1320+
def rename(
1321+
self,
1322+
new_name: str,
1323+
inplace: bool = True,
1324+
) -> "vDataFrame":
13211325
"""
1322-
Renames the vDataColumn by dropping the current vDataColumn
1323-
and creating a copy with the specified name.
1326+
Renames the vDataColumn. This function is not
1327+
directly applied to the input object.
13241328
13251329
.. warning::
13261330
13271331
SQL code generation will be slower if the
13281332
vDataFrame has been transformed multiple
13291333
times, so it's better practice to use this
13301334
method when first preparing your data.
1335+
It is even recommended to use directly
1336+
``vDataFrame.``:py:meth:`~verticapy.vDataFrame.select`
1337+
method and do all the renaming within
1338+
one single operation.
13311339
13321340
Parameters
13331341
----------
13341342
new_name: str
13351343
The new vDataColumn alias.
1344+
inplace: bool, optional
1345+
If set to ``True``, the
1346+
:py:class:`~vDataFrame` is replaced
1347+
with the new relation.
13361348
13371349
Returns
13381350
-------
13391351
vDataFrame
1340-
self._parent
1352+
result.
13411353
13421354
Examples
13431355
--------
@@ -1385,8 +1397,7 @@ def rename(self, new_name: str) -> "vDataFrame":
13851397
.. ipython:: python
13861398
:suppress:
13871399
1388-
vdf["val"].rename("value")
1389-
result = vdf
1400+
result = vdf["val"].rename("value", inplace=False)
13901401
html_file = open("SPHINX_DIRECTORY/figures/core_vDataFrame_sys_rename.html", "w")
13911402
html_file.write(result._repr_html_())
13921403
html_file.close()
@@ -1407,9 +1418,11 @@ def rename(self, new_name: str) -> "vDataFrame":
14071418
"By changing the parameter 'new_name', you'll "
14081419
"be able to solve this issue."
14091420
)
1410-
self._parent.eval(name=new_name, expr=old_name)
1411-
parent = self.drop(add_history=False)
1412-
parent._add_to_history(
1413-
f"[Rename]: The vDataColumn {old_name} was renamed '{new_name}'."
1421+
res = self._parent.select(
1422+
self._parent.get_columns(exclude_columns=[old_name])
1423+
+ [f"{old_name} AS {new_name}"]
14141424
)
1415-
return parent
1425+
if inplace:
1426+
self._parent.__init__(res.current_relation())
1427+
return self._parent
1428+
return res

verticapy/plotting/_matplotlib/bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def draw(
7878
xticks_label = xticks
7979
ax.set_xticks(xticks)
8080
ax.set_xticklabels(xticks_label, rotation=90)
81-
ax.set_ylabel(self.layout["method"])
81+
ax.set_ylabel(self.layout["method_of"])
8282
return ax
8383

8484

@@ -151,7 +151,7 @@ def draw(
151151
ax.set_xticks(xticks)
152152
ax.set_xticklabels(self.layout["x_labels"], rotation=90)
153153
ax.set_xlabel(self.layout["columns"][0])
154-
ax.set_ylabel(self.layout["method"])
154+
ax.set_ylabel(self.layout["method_of"])
155155
ax.legend(
156156
title=self.layout["columns"][1], loc="center left", bbox_to_anchor=[1, 0.5]
157157
)

verticapy/plotting/_matplotlib/barh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def draw(
7676
ax.set_yticks(
7777
[x - round(self.data["width"] / 2, 10) for x in self.data["x"]]
7878
)
79-
ax.set_xlabel(self.layout["method"])
79+
ax.set_xlabel(self.layout["method_of"])
8080
return ax
8181

8282

@@ -187,7 +187,7 @@ def draw(
187187
ax.set_yticks(yticks)
188188
ax.set_yticklabels(self.layout["x_labels"])
189189
ax.set_ylabel(self.layout["columns"][0])
190-
ax.set_xlabel(self.layout["method"])
190+
ax.set_xlabel(self.layout["method_of"])
191191
if self.layout["kind"] in ("density", "fully_stacked"):
192192
vals = ax.get_xticks()
193193
max_val = max(abs(x) for x in vals)

verticapy/plotting/_matplotlib/pie.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def draw(
112112
):
113113
current_explode = min(0.9, current_explode * 1.4)
114114
explode[idx] = current_explode
115-
if self.layout["method"].lower() == "density":
115+
if str(self.layout["method"]).lower() == "density":
116116
autopct = "%1.1f%%"
117117
else:
118-
if (self.layout["method"].lower() in ["sum", "count"]) or (
119-
(self.layout["method"].lower() in ["min", "max"])
118+
if (str(self.layout["method"]).lower() in ["sum", "count"]) or (
119+
(str(self.layout["method"]).lower() in ["min", "max"])
120120
and (self.layout["of_cat"] == "int")
121121
):
122122
category = "int"

verticapy/plotting/_matplotlib/spider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def draw(
9090
ax.set_yticks(y_ticks)
9191
ax.set_rgrids(y_ticks, angle=180.0, fmt="%0.1f")
9292
ax.set_xlabel(self.layout["columns"][0])
93-
ax.set_ylabel(self.layout["method"])
93+
ax.set_ylabel(self.layout["method_of"])
9494
if len(self.layout["columns"]) > 1:
9595
ax.legend(
9696
title=self.layout["columns"][1],

verticapy/plotting/_plotly/bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _compute_method(self) -> Literal["1D"]:
4343
def _init_style(self) -> None:
4444
self.init_trace_style = {"marker_color": self.get_colors(idx=0)}
4545
self.init_layout_style = {
46-
"yaxis_title": self.layout["method"],
46+
"yaxis_title": self.layout["method_of"],
4747
"xaxis_title": self.layout["column"],
4848
"width": 100 + 100 * len(self.layout["labels"]),
4949
"height": 500,
@@ -90,7 +90,7 @@ def _compute_method(self) -> Literal["2D"]:
9090
# Styling Methods.
9191
def _init_style(self) -> None:
9292
self.init_layout_style = {
93-
"yaxis_title": self.layout["method"],
93+
"yaxis_title": self.layout["method_of"],
9494
"legend_title_text": self.layout["columns"][1],
9595
"xaxis_title": self.layout["columns"][0],
9696
"width": (150 + 40 * len(self.layout["x_labels"]))

verticapy/plotting/_plotly/barh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _compute_method(self) -> Literal["1D"]:
4444
def _init_style(self) -> None:
4545
self.init_trace_style = {"marker_color": self.get_colors(idx=0)}
4646
self.init_layout_style = {
47-
"xaxis_title": self.layout["method"],
47+
"xaxis_title": self.layout["method_of"],
4848
"yaxis_title": self.layout["column"],
4949
# "width": 500 ,
5050
"height": 100 * len(self.layout["labels"]),
@@ -89,7 +89,7 @@ def _compute_method(self) -> Literal["2D"]:
8989

9090
def _init_style(self) -> None:
9191
self.init_layout_style = {
92-
"xaxis_title": self.layout["method"],
92+
"xaxis_title": self.layout["method_of"],
9393
"legend_title_text": self.layout["columns"][1],
9494
"yaxis_title": self.layout["columns"][0],
9595
"width": 500,

verticapy/plotting/_plotly/pie.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ def _init_style(self) -> None:
4444
"hovertemplate": "%{label} <extra></extra>",
4545
}
4646
self.init_layout_style = {
47-
"title_text": self.layout["column"],
47+
"title_text": self.layout["method_of"],
4848
"title_x": 0.5,
4949
"title_xanchor": "center",
50+
"legend": {"title": self.layout["column"]},
5051
}
5152

5253
# Draw

0 commit comments

Comments
 (0)