Skip to content

Commit 9d970d7

Browse files
committed
fixed major bugs in stairs, report and plot_heatmap methods
1 parent 4e8452f commit 9d970d7

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ classifiers =
1313
License :: OSI Approved :: MIT License
1414
Operating System :: OS Independent
1515
Programming Language :: Python :: 3
16-
Programming Language :: Python :: 3.5
1716
Programming Language :: Python :: 3.6
1817
Programming Language :: Python :: 3.7
1918
Programming Language :: Python :: 3.8
2019
Programming Language :: Python :: 3.9
2120
Programming Language :: Python :: 3.10
21+
Programming Language :: Python :: 3.11
2222
Topic :: Scientific/Engineering :: Information Analysis
2323

2424
[options]

src/scikit_na/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from ._stats import * # noqa: F401, F403
55
from ._report import * # noqa: F401, F403
66

7-
__version__ = '0.1.0'
7+
__version__ = '0.1.1'

src/scikit_na/_report.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _on_vis_col_select(names):
114114

115115
select_vis_cols = widgets.SelectMultiple(options=cols, rows=6)
116116
select_vis_cols.observe(_on_vis_col_select, names='value')
117-
select_vis_accordion = widgets.Accordion(children=[select_cols])
117+
select_vis_accordion = widgets.Accordion(children=[select_vis_cols])
118118
select_vis_accordion.set_title(0, 'Columns selection')
119119
select_vis_accordion.selected_index = 0
120120

@@ -147,6 +147,7 @@ def _on_vis_col_select(names):
147147
def _on_stats_col_select(_):
148148
# Clearing display
149149
stats_table.clear_output(wait=False)
150+
stats_table2.clear_output(wait=False)
150151
# Getting selected column with NA values
151152
_col_na = select_stats_col_na.value
152153
# Getting selected columns
@@ -157,15 +158,21 @@ def _on_stats_col_select(_):
157158
_cols_nominal = _get_nominal_cols(data, _cols)
158159

159160
with stats_table:
160-
display(
161-
describe(
162-
data, col_na=_col_na, columns=_cols_numeric)
163-
.round(round_dec))
161+
try:
162+
display(
163+
describe(
164+
data, col_na=_col_na, columns=_cols_numeric)
165+
.round(round_dec))
166+
except:
167+
display(widgets.HTML('Please select numeric columns to describe'))
164168
with stats_table2:
165-
display(
166-
describe(
167-
data, col_na=_col_na, columns=_cols_nominal)
168-
.round(round_dec))
169+
try:
170+
display(
171+
describe(
172+
data, col_na=_col_na, columns=_cols_nominal)
173+
.round(round_dec))
174+
except:
175+
display(widgets.HTML('Please select nominal columns to describe'))
169176

170177
# Setting up dropdown and select elements for choosing columns
171178
select_stats_col_na_header = widgets.HTML(

src/scikit_na/_stats.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def _select_cols(
1515
return array(
1616
list(col for col in columns)
1717
if columns is not None
18-
else (data.columns if second_var is None else second_var))
18+
else (data.columns if second_var is None or len(second_var) == 0 else second_var))
1919

2020

2121
def _get_nominal_cols(
@@ -106,7 +106,7 @@ def summary(
106106
"""
107107
cols = _select_cols(data, columns)
108108
data_copy = data.loc[:, cols].copy()
109-
na_by_inst = (data_copy.isna().sum(axis=1) == 1)
109+
na_by_inst = data_copy.isna().sum(axis=1) == 1
110110
na_total = _get_total_na_count(data_copy, cols)
111111

112112
if per_column:
@@ -201,8 +201,8 @@ def stairs(
201201
Dataset shrinkage results after cumulative
202202
:py:meth:`pandas.DataFrame.dropna()`.
203203
"""
204-
data_copy = data.copy()
205204
cols = _select_cols(data, columns).tolist()
205+
data_copy = data.loc[:, cols].copy()
206206
stairs_values = []
207207
stairs_labels = []
208208

src/scikit_na/altair/_altair.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Optional, Sequence
66
from numbers import Integral
77
from ipywidgets import widgets, interact
8-
from numpy import arange, r_, nan, fill_diagonal
8+
from numpy import arange, nan, fill_diagonal
99
from pandas import DataFrame
1010
from altair import (
1111
Axis, Chart, Color, condition, data_transformers, selection_multi,
@@ -401,7 +401,7 @@ def plot_stairs(
401401
x=X(**x_kws),
402402
y=Y(**y_kws),
403403
tooltip=[xlabel, ylabel, tooltip_label]
404-
)
404+
)
405405
return chart\
406406
.configure_axis(labelFontSize=font_size, titleFontSize=font_size)\
407407
.configure_legend(labelFontSize=font_size, titleFontSize=font_size)
@@ -472,17 +472,15 @@ def plot_stairbars(
472472
x=X(**x_kws),
473473
y=Y(**y_kws),
474474
tooltip=[xlabel, ylabel, tooltip_label]
475-
)
475+
)
476476
return chart\
477477
.configure_axis(labelFontSize=font_size, titleFontSize=font_size)\
478478
.configure_legend(labelFontSize=font_size, titleFontSize=font_size)
479479

480480

481-
482481
def plot_heatmap(
483482
data: DataFrame,
484483
columns: Optional[Sequence[str]] = None,
485-
tooltip_cols: Optional[Sequence[str]] = None,
486484
names: list = None,
487485
sort: bool = True,
488486
droppable: bool = True,
@@ -506,8 +504,6 @@ def plot_heatmap(
506504
Input data.
507505
columns : Optional[Sequence[str]], optional
508506
Columns that are to be displayed on a plot.
509-
tooltip_cols : Optional[Sequence[str]], optional
510-
Columns to be used in tooltips.
511507
names : list, optional
512508
Values labels passed as a list.
513509
The first element corresponds to non-missing values,
@@ -545,7 +541,8 @@ def plot_heatmap(
545541
if not x_kws:
546542
x_kws = {'sort': None, 'shorthand': xlabel, 'type': 'nominal'}
547543
if not y_kws:
548-
y_kws = {'sort': None, 'shorthand': ylabel, 'type': 'ordinal', 'axis': Axis(labelOverlap='greedy')}
544+
y_kws = {'sort': None, 'shorthand': ylabel,
545+
'type': 'ordinal', 'axis': Axis(labelOverlap='greedy')}
549546
if not names:
550547
names = ['Filled', 'NA', 'Droppable']
551548
if not color_kws:
@@ -557,37 +554,35 @@ def plot_heatmap(
557554
range=["green", "red", "orange"])
558555
}
559556
if not rect_kws:
560-
rect_kws = {}
557+
rect_kws = {"clip": True}
561558

562559
cols = _select_cols(data, columns)
563-
tt_cols = _select_cols(data, tooltip_cols, [])
564560

565-
data_copy = data.loc[:, r_[cols, tt_cols]].copy()
566-
data_copy.loc[:, cols] = data_copy.loc[:, cols].isna()
561+
data_copy = data.loc[:, cols].copy().isna()
567562
if sort:
568-
cols_sorted = data_copy.loc[:, cols]\
563+
cols_sorted = data_copy\
569564
.sum()\
570565
.sort_values(ascending=False)\
571566
.index.tolist()
572567
data_copy.sort_values(by=cols_sorted, inplace=True)
573568
x_kws.update({'sort': cols_sorted})
574569

575570
if droppable:
576-
non_na_mask = ~data_copy.loc[:, cols].values
577-
na_rows_mask = data_copy.loc[:, cols].any(axis=1).values[:, None]
571+
non_na_mask = ~data_copy.values
572+
na_rows_mask = data_copy.any(
573+
axis=1).values[:, None]
578574
droppable_mask = non_na_mask & na_rows_mask
579-
data_copy.loc[:, cols] = data_copy.loc[:, cols].astype(int)
580-
data_copy.loc[:, cols] = data_copy.loc[:, cols]\
575+
data_copy = data_copy.astype(int)\
581576
.mask(droppable_mask, other=2)
582577
else:
583-
data_copy.loc[:, cols] = data_copy.loc[:, cols].astype(int)
578+
data_copy = data_copy.astype(int)
584579

585-
data_copy.loc[:, cols] = data_copy.loc[:, cols].replace(
580+
data_copy = data_copy.replace(
586581
dict(zip([0, 1, 2], names)))
587582

588583
data_copy[ylabel] = arange(data.shape[0])
589584
data_copy = data_copy.melt(
590-
id_vars=r_[[ylabel], tt_cols],
585+
id_vars=[ylabel],
591586
value_vars=cols,
592587
var_name=xlabel,
593588
value_name=zlabel)
@@ -598,8 +593,7 @@ def plot_heatmap(
598593
x=X(**x_kws),
599594
y=Y(**y_kws),
600595
color=Color(**color_kws),
601-
tooltip=tt_cols.tolist()
602-
)
596+
)
603597

604598
return chart\
605599
.configure_axis(labelFontSize=font_size, titleFontSize=font_size)\

0 commit comments

Comments
 (0)