Cannot style.background_gradient
on an Int64
column · Issue #28869 · pandas-dev/pandas (original) (raw)
old = pd.Series(range(9)) new = pd.Series(range(9), dtype='Int64')
print(old.min(), old.values.min(), new.min()) # =0 OK print(new.values.min()) # KO
old.to_frame().style.background_gradient() # OK new.to_frame().style.background_gradient() # KO
Similarly to #25580, the newer Int64 backend is missing some basic functionality.
AttributeError Traceback (most recent call last)
~/virtualenvs/jupyter/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/io/formats/style.py in _repr_html_(self)
161 Hooks into Jupyter notebook rich display system.
162 """
--> 163 return self.render()
164
165 @Appender(_shared_docs['to_excel'] % dict(
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/io/formats/style.py in render(self, **kwargs)
457 * table_attributes
458 """
--> 459 self._compute()
460 # TODO: namespace all the pandas keys
461 d = self._translate()
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/io/formats/style.py in _compute(self)
527 r = self
528 for func, args, kwargs in self._todo:
--> 529 r = func(self)(*args, **kwargs)
530 return r
531
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/io/formats/style.py in _apply(self, func, axis, subset, **kwargs)
536 if axis is not None:
537 result = data.apply(func, axis=axis,
--> 538 result_type='expand', **kwargs)
539 result.columns = data.columns
540 else:
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
6485 args=args,
6486 kwds=kwds)
-> 6487 return op.get_result()
6488
6489 def applymap(self, func):
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/core/apply.py in get_result(self)
149 return self.apply_raw()
150
--> 151 return self.apply_standard()
152
153 def apply_empty_result(self):
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/core/apply.py in apply_standard(self)
255
256 # compute the result using the series generator
--> 257 self.apply_series_generator()
258
259 # wrap results
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/core/apply.py in apply_series_generator(self)
284 try:
285 for i, v in enumerate(series_gen):
--> 286 results[i] = self.f(v)
287 keys.append(v.name)
288 except Exception as e:
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/core/apply.py in f(x)
76
77 def f(x):
---> 78 return func(x, *args, **kwds)
79 else:
80 f = func
~/virtualenvs/jupyter/lib/python3.6/site-packages/pandas/io/formats/style.py in _background_gradient(s, cmap, low, high, text_color_threshold)
939
940 with _mpl(Styler.background_gradient) as (plt, colors):
--> 941 smin = s.values.min()
942 smax = s.values.max()
943 rng = smax - smin
AttributeError: ("'IntegerArray' object has no attribute 'min'", 'occurred at index 0')