Skip to content

Commit

Permalink
Don't change writeable flag on array in CategoricalComponents since t…
Browse files Browse the repository at this point in the history
…his can cause issues when the underlying buffer is read-only
  • Loading branch information
astrofrog committed Feb 27, 2018
1 parent 7e6dd9d commit dd5ed96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 0 additions & 3 deletions glue/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,6 @@ def __init__(self, categorical_data, categories=None, jitter=None, units=None):
if self._categorical_data.ndim > 1:
raise ValueError("Categorical Data must be 1-dimensional")

# Disable changing of categories
self._categorical_data.setflags(write=False)

self._categories = categories
self._jitter_method = jitter
self._is_jittered = False
Expand Down
9 changes: 9 additions & 0 deletions glue/core/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ def test_accepts_numpy(self):
cat_comp = CategoricalComponent(self.array_data)
assert cat_comp._categorical_data.shape == (4,)

def test_accepts_pandas(self):
# Regression test for a bug that caused read-only
# pandas DataFrame columns to cause issues
from pandas import DataFrame
df = DataFrame()
df['a'] = ['a', 'b', 'c']
print(df['a'].fillna(''), type)
CategoricalComponent(df['a'].fillna(''))

def test_accepts_list(self):
"""Should accept a list and convert to numpy!"""
cat_comp = CategoricalComponent(self.list_data)
Expand Down

0 comments on commit dd5ed96

Please sign in to comment.