charty 0.1.5.dev → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +71 -0
  3. data/.github/workflows/nmatrix.yml +67 -0
  4. data/.github/workflows/pycall.yml +86 -0
  5. data/Dockerfile.dev +9 -1
  6. data/Gemfile +18 -0
  7. data/README.md +176 -9
  8. data/Rakefile +4 -5
  9. data/charty.gemspec +10 -1
  10. data/examples/Gemfile +1 -0
  11. data/examples/active_record.ipynb +1 -1
  12. data/examples/daru.ipynb +1 -1
  13. data/examples/iris_dataset.ipynb +1 -1
  14. data/examples/nmatrix.ipynb +1 -1
  15. data/examples/{numo-narray.ipynb → numo_narray.ipynb} +1 -1
  16. data/examples/palette.rb +71 -0
  17. data/examples/sample.png +0 -0
  18. data/examples/sample_bokeh.ipynb +156 -0
  19. data/examples/sample_google_chart.ipynb +229 -68
  20. data/examples/sample_images/bar_bokeh.html +85 -0
  21. data/examples/sample_images/barh_bokeh.html +85 -0
  22. data/examples/sample_images/box_plot_bokeh.html +85 -0
  23. data/examples/sample_images/curve_bokeh.html +85 -0
  24. data/examples/sample_images/curve_with_function_bokeh.html +85 -0
  25. data/examples/sample_images/hist_gruff.png +0 -0
  26. data/examples/sample_images/scatter_bokeh.html +85 -0
  27. data/examples/sample_pyplot.ipynb +40 -38
  28. data/images/penguins_body_mass_g_flipper_length_mm_scatter_plot.png +0 -0
  29. data/images/penguins_body_mass_g_flipper_length_mm_species_scatter_plot.png +0 -0
  30. data/images/penguins_body_mass_g_flipper_length_mm_species_sex_scatter_plot.png +0 -0
  31. data/images/penguins_species_body_mass_g_bar_plot_h.png +0 -0
  32. data/images/penguins_species_body_mass_g_bar_plot_v.png +0 -0
  33. data/images/penguins_species_body_mass_g_box_plot_h.png +0 -0
  34. data/images/penguins_species_body_mass_g_box_plot_v.png +0 -0
  35. data/images/penguins_species_body_mass_g_sex_bar_plot_v.png +0 -0
  36. data/images/penguins_species_body_mass_g_sex_box_plot_v.png +0 -0
  37. data/lib/charty.rb +14 -1
  38. data/lib/charty/backend_methods.rb +8 -0
  39. data/lib/charty/backends.rb +80 -0
  40. data/lib/charty/backends/bokeh.rb +32 -26
  41. data/lib/charty/backends/google_charts.rb +267 -0
  42. data/lib/charty/backends/gruff.rb +102 -83
  43. data/lib/charty/backends/plotly.rb +685 -0
  44. data/lib/charty/backends/pyplot.rb +586 -92
  45. data/lib/charty/backends/rubyplot.rb +82 -74
  46. data/lib/charty/backends/unicode_plot.rb +79 -0
  47. data/lib/charty/index.rb +213 -0
  48. data/lib/charty/linspace.rb +1 -1
  49. data/lib/charty/missing_value_support.rb +14 -0
  50. data/lib/charty/plot_methods.rb +184 -0
  51. data/lib/charty/plotter.rb +48 -40
  52. data/lib/charty/plotters.rb +11 -0
  53. data/lib/charty/plotters/abstract_plotter.rb +183 -0
  54. data/lib/charty/plotters/bar_plotter.rb +201 -0
  55. data/lib/charty/plotters/box_plotter.rb +79 -0
  56. data/lib/charty/plotters/categorical_plotter.rb +380 -0
  57. data/lib/charty/plotters/count_plotter.rb +7 -0
  58. data/lib/charty/plotters/estimation_support.rb +84 -0
  59. data/lib/charty/plotters/random_support.rb +25 -0
  60. data/lib/charty/plotters/relational_plotter.rb +518 -0
  61. data/lib/charty/plotters/scatter_plotter.rb +104 -0
  62. data/lib/charty/plotters/vector_plotter.rb +6 -0
  63. data/lib/charty/statistics.rb +114 -0
  64. data/lib/charty/table.rb +80 -3
  65. data/lib/charty/table_adapters.rb +25 -0
  66. data/lib/charty/table_adapters/active_record_adapter.rb +63 -0
  67. data/lib/charty/table_adapters/base_adapter.rb +69 -0
  68. data/lib/charty/table_adapters/daru_adapter.rb +70 -0
  69. data/lib/charty/table_adapters/datasets_adapter.rb +49 -0
  70. data/lib/charty/table_adapters/hash_adapter.rb +224 -0
  71. data/lib/charty/table_adapters/narray_adapter.rb +76 -0
  72. data/lib/charty/table_adapters/nmatrix_adapter.rb +67 -0
  73. data/lib/charty/table_adapters/pandas_adapter.rb +81 -0
  74. data/lib/charty/util.rb +20 -0
  75. data/lib/charty/vector.rb +69 -0
  76. data/lib/charty/vector_adapters.rb +183 -0
  77. data/lib/charty/vector_adapters/array_adapter.rb +109 -0
  78. data/lib/charty/vector_adapters/daru_adapter.rb +171 -0
  79. data/lib/charty/vector_adapters/narray_adapter.rb +187 -0
  80. data/lib/charty/vector_adapters/nmatrix_adapter.rb +37 -0
  81. data/lib/charty/vector_adapters/numpy_adapter.rb +168 -0
  82. data/lib/charty/vector_adapters/pandas_adapter.rb +200 -0
  83. data/lib/charty/version.rb +1 -1
  84. metadata +179 -10
  85. data/.travis.yml +0 -11
  86. data/lib/charty/backends/google_chart.rb +0 -167
  87. data/lib/charty/plotter_adapter.rb +0 -17
@@ -0,0 +1,200 @@
1
+ module Charty
2
+ module VectorAdapters
3
+ class PandasSeriesAdapter < BaseAdapter
4
+ VectorAdapters.register(:pandas_series, self)
5
+
6
+ def self.supported?(data)
7
+ return false unless defined?(Pandas::Series)
8
+ case data
9
+ when Pandas::Series
10
+ true
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ def initialize(data)
17
+ @data = check_data(data)
18
+ end
19
+
20
+ attr_reader :data
21
+
22
+ def_delegator :data, :size, :length
23
+
24
+ def index
25
+ PandasIndex.new(data.index)
26
+ end
27
+
28
+ def index=(new_index)
29
+ case new_index
30
+ when PandasIndex
31
+ data.index = new_index.values
32
+ when Index
33
+ data.index = new_index.to_a
34
+ else
35
+ data.index = new_index
36
+ end
37
+ end
38
+
39
+ def_delegators :data, :name, :name=
40
+
41
+ def compare_data_equality(other)
42
+ case other
43
+ when PandasSeriesAdapter
44
+ return data.equals(other.data)
45
+ when NumpyAdapter
46
+ other = other.data
47
+ when NArrayAdapter
48
+ case other.data
49
+ when Numo::Bit
50
+ other = other.data.to_a
51
+ other.map! {|x| [false, true][x] }
52
+ else
53
+ other = other.data.to_a
54
+ end
55
+ when BaseAdapter
56
+ other = other.data.to_a
57
+ else
58
+ return false
59
+ end
60
+
61
+ data.equals(Pandas::Series.new(other, index: data.index))
62
+ end
63
+
64
+ def [](key)
65
+ case key
66
+ when Charty::Vector
67
+ where(key)
68
+ else
69
+ data[key]
70
+ end
71
+ end
72
+
73
+ def_delegators :data, :[]=, :to_a
74
+
75
+ def each
76
+ return enum_for(__method__) unless block_given?
77
+
78
+ i, n = 0, data.size
79
+ while i < n
80
+ yield data.iloc[i]
81
+ i += 1
82
+ end
83
+ end
84
+
85
+ def empty?
86
+ data.size == 0
87
+ end
88
+
89
+ # TODO: Reconsider the return value type of values_at
90
+ def values_at(*indices)
91
+ data.take(indices).to_a
92
+ end
93
+
94
+ def where(mask)
95
+ mask = check_mask_vector(mask)
96
+ case mask.data
97
+ when Numpy::NDArray,
98
+ ->(x) { defined?(Pandas::Series) && x.is_a?(Pandas::Series) }
99
+ mask_data = Numpy.asarray(mask.data, dtype: :bool)
100
+ masked_data = data[mask_data]
101
+ masked_index = mask_data.nonzero()[0].to_a.map {|i| index[i] }
102
+ else
103
+ masked_data, masked_index = where_in_array(mask)
104
+ masked_data = Pandas::Series.new(masked_data, dtype: data.dtype)
105
+ end
106
+ Charty::Vector.new(masked_data, index: masked_index, name: name)
107
+ end
108
+
109
+ def where_in_array(mask)
110
+ mask = check_mask_vector(mask)
111
+ masked_data = []
112
+ masked_index = []
113
+ mask.each_with_index do |f, i|
114
+ case f
115
+ when true, 1
116
+ masked_data << data.iloc[i]
117
+ masked_index << index[i]
118
+ end
119
+ end
120
+ return masked_data, masked_index
121
+ end
122
+
123
+ def boolean?
124
+ case
125
+ when Pandas.api.types.is_bool_dtype(data.dtype)
126
+ true
127
+ when Pandas.api.types.is_object_dtype(data.dtype)
128
+ data.isin([nil, false, true]).all()
129
+ else
130
+ false
131
+ end
132
+ end
133
+
134
+ def numeric?
135
+ Pandas.api.types.is_numeric_dtype(data.dtype)
136
+ end
137
+
138
+ def categorical?
139
+ Pandas.api.types.is_categorical_dtype(data.dtype)
140
+ end
141
+
142
+ def categories
143
+ data.cat.categories.to_a if categorical?
144
+ end
145
+
146
+ def unique_values
147
+ data.unique.to_a
148
+ end
149
+
150
+ def group_by(grouper)
151
+ case grouper
152
+ when Pandas::Series
153
+ group_keys = grouper.unique.to_a
154
+ groups = data.groupby(grouper)
155
+ group_keys.map {|g|
156
+ [g, Charty::Vector.new(groups.get_group(g))]
157
+ }.to_h
158
+ when Charty::Vector
159
+ case grouper.adapter
160
+ when self.class
161
+ group_by(grouper.data)
162
+ else
163
+ grouper = Pandas::Series.new(grouper.to_a)
164
+ group_by(grouper)
165
+ end
166
+ else
167
+ grouper = Pandas::Series.new(Array(grouper))
168
+ group_by(grouper)
169
+ end
170
+ end
171
+
172
+ def drop_na
173
+ Charty::Vector.new(data.dropna)
174
+ end
175
+
176
+ def eq(val)
177
+ Charty::Vector.new((data == val),
178
+ index: index,
179
+ name: name)
180
+ end
181
+
182
+ def notnull
183
+ Charty::Vector.new(data.notnull, index: index, name: name)
184
+ end
185
+
186
+ def mean
187
+ data.mean()
188
+ end
189
+
190
+ def stdev(population: false)
191
+ data.std(ddof: population ? 0 : 1)
192
+ end
193
+
194
+ def percentile(q)
195
+ q = q.map {|x| x / 100.0 }
196
+ data.quantile(q)
197
+ end
198
+ end
199
+ end
200
+ end
@@ -1,5 +1,5 @@
1
1
  module Charty
2
- VERSION = "0.1.5-dev"
2
+ VERSION = "0.2.5"
3
3
 
4
4
  module Version
5
5
  numbers, TAG = VERSION.split("-")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5.dev
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
@@ -10,8 +10,36 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-07-09 00:00:00.000000000 Z
13
+ date: 2021-05-28 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: red-colors
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: red-palette
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.2.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.2.0
15
43
  - !ruby/object:Gem::Dependency
16
44
  name: bundler
17
45
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +83,91 @@ dependencies:
55
83
  - !ruby/object:Gem::Version
56
84
  version: '0'
57
85
  - !ruby/object:Gem::Dependency
58
- name: matplotlib
86
+ name: red-datasets
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 0.0.9
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 0.0.9
99
+ - !ruby/object:Gem::Dependency
100
+ name: daru
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: matrix
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: activerecord
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: sqlite3
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: playwright-ruby-client
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: iruby
59
171
  requirement: !ruby/object:Gem::Requirement
60
172
  requirements:
61
173
  - - ">="
@@ -77,8 +189,10 @@ executables: []
77
189
  extensions: []
78
190
  extra_rdoc_files: []
79
191
  files:
192
+ - ".github/workflows/ci.yml"
193
+ - ".github/workflows/nmatrix.yml"
194
+ - ".github/workflows/pycall.yml"
80
195
  - ".gitignore"
81
- - ".travis.yml"
82
196
  - Dockerfile.dev
83
197
  - Gemfile
84
198
  - LICENSE
@@ -93,24 +207,34 @@ files:
93
207
  - examples/daru.ipynb
94
208
  - examples/iris_dataset.ipynb
95
209
  - examples/nmatrix.ipynb
96
- - examples/numo-narray.ipynb
210
+ - examples/numo_narray.ipynb
211
+ - examples/palette.rb
212
+ - examples/sample.png
213
+ - examples/sample_bokeh.ipynb
97
214
  - examples/sample_google_chart.ipynb
98
215
  - examples/sample_gruff.ipynb
216
+ - examples/sample_images/bar_bokeh.html
99
217
  - examples/sample_images/bar_gruff.png
100
218
  - examples/sample_images/bar_pyplot.png
101
219
  - examples/sample_images/bar_rubyplot.png
220
+ - examples/sample_images/barh_bokeh.html
102
221
  - examples/sample_images/barh_gruff.png
103
222
  - examples/sample_images/barh_pyplot.png
223
+ - examples/sample_images/box_plot_bokeh.html
104
224
  - examples/sample_images/box_plot_pyplot.png
105
225
  - examples/sample_images/bubble_pyplot.png
106
226
  - examples/sample_images/bubble_rubyplot.png
227
+ - examples/sample_images/curve_bokeh.html
107
228
  - examples/sample_images/curve_gruff.png
108
229
  - examples/sample_images/curve_pyplot.png
109
230
  - examples/sample_images/curve_rubyplot.png
231
+ - examples/sample_images/curve_with_function_bokeh.html
110
232
  - examples/sample_images/curve_with_function_pyplot.png
111
233
  - examples/sample_images/curve_with_function_rubyplot.png
112
234
  - examples/sample_images/error_bar_pyplot.png
235
+ - examples/sample_images/hist_gruff.png
113
236
  - examples/sample_images/hist_pyplot.png
237
+ - examples/sample_images/scatter_bokeh.html
114
238
  - examples/sample_images/scatter_gruff.png
115
239
  - examples/sample_images/scatter_pyplot.png
116
240
  - examples/sample_images/scatter_rubyplot.png
@@ -119,17 +243,62 @@ files:
119
243
  - examples/sample_pyplot.ipynb
120
244
  - examples/sample_rubyplot.ipynb
121
245
  - images/design_concept.png
246
+ - images/penguins_body_mass_g_flipper_length_mm_scatter_plot.png
247
+ - images/penguins_body_mass_g_flipper_length_mm_species_scatter_plot.png
248
+ - images/penguins_body_mass_g_flipper_length_mm_species_sex_scatter_plot.png
249
+ - images/penguins_species_body_mass_g_bar_plot_h.png
250
+ - images/penguins_species_body_mass_g_bar_plot_v.png
251
+ - images/penguins_species_body_mass_g_box_plot_h.png
252
+ - images/penguins_species_body_mass_g_box_plot_v.png
253
+ - images/penguins_species_body_mass_g_sex_bar_plot_v.png
254
+ - images/penguins_species_body_mass_g_sex_box_plot_v.png
122
255
  - lib/charty.rb
256
+ - lib/charty/backend_methods.rb
257
+ - lib/charty/backends.rb
123
258
  - lib/charty/backends/bokeh.rb
124
- - lib/charty/backends/google_chart.rb
259
+ - lib/charty/backends/google_charts.rb
125
260
  - lib/charty/backends/gruff.rb
261
+ - lib/charty/backends/plotly.rb
126
262
  - lib/charty/backends/pyplot.rb
127
263
  - lib/charty/backends/rubyplot.rb
264
+ - lib/charty/backends/unicode_plot.rb
265
+ - lib/charty/index.rb
128
266
  - lib/charty/layout.rb
129
267
  - lib/charty/linspace.rb
268
+ - lib/charty/missing_value_support.rb
269
+ - lib/charty/plot_methods.rb
130
270
  - lib/charty/plotter.rb
131
- - lib/charty/plotter_adapter.rb
271
+ - lib/charty/plotters.rb
272
+ - lib/charty/plotters/abstract_plotter.rb
273
+ - lib/charty/plotters/bar_plotter.rb
274
+ - lib/charty/plotters/box_plotter.rb
275
+ - lib/charty/plotters/categorical_plotter.rb
276
+ - lib/charty/plotters/count_plotter.rb
277
+ - lib/charty/plotters/estimation_support.rb
278
+ - lib/charty/plotters/random_support.rb
279
+ - lib/charty/plotters/relational_plotter.rb
280
+ - lib/charty/plotters/scatter_plotter.rb
281
+ - lib/charty/plotters/vector_plotter.rb
282
+ - lib/charty/statistics.rb
132
283
  - lib/charty/table.rb
284
+ - lib/charty/table_adapters.rb
285
+ - lib/charty/table_adapters/active_record_adapter.rb
286
+ - lib/charty/table_adapters/base_adapter.rb
287
+ - lib/charty/table_adapters/daru_adapter.rb
288
+ - lib/charty/table_adapters/datasets_adapter.rb
289
+ - lib/charty/table_adapters/hash_adapter.rb
290
+ - lib/charty/table_adapters/narray_adapter.rb
291
+ - lib/charty/table_adapters/nmatrix_adapter.rb
292
+ - lib/charty/table_adapters/pandas_adapter.rb
293
+ - lib/charty/util.rb
294
+ - lib/charty/vector.rb
295
+ - lib/charty/vector_adapters.rb
296
+ - lib/charty/vector_adapters/array_adapter.rb
297
+ - lib/charty/vector_adapters/daru_adapter.rb
298
+ - lib/charty/vector_adapters/narray_adapter.rb
299
+ - lib/charty/vector_adapters/nmatrix_adapter.rb
300
+ - lib/charty/vector_adapters/numpy_adapter.rb
301
+ - lib/charty/vector_adapters/pandas_adapter.rb
133
302
  - lib/charty/version.rb
134
303
  homepage: https://github.com/red-data-tools/charty
135
304
  licenses:
@@ -146,11 +315,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
315
  version: '0'
147
316
  required_rubygems_version: !ruby/object:Gem::Requirement
148
317
  requirements:
149
- - - ">"
318
+ - - ">="
150
319
  - !ruby/object:Gem::Version
151
- version: 1.3.1
320
+ version: '0'
152
321
  requirements: []
153
- rubygems_version: 3.0.3
322
+ rubygems_version: 3.2.3
154
323
  signing_key:
155
324
  specification_version: 4
156
325
  summary: Visualizing your data in a simple way.