Repository: rootpy/rootpy

Issue:
Not valid fill style (root2hdf5 bug)
When using `root2hdf5` (script or function), I get `ValueError: 101 is not a valid fill style` when I try to convert a GEANT4 produced root file. By adding `101:None` to the dictionary in `rootpy/plotting/base.py`, I can fix the error and it converts fine. The list does contain 1001, but not 101.

Seems like rootpy should not even be touching the histograms or trying to connect to the graphical server at all when converting trees with this method.

Another fix would be to simply print a warning and continue with no fill if fill style is not recognized. I could put together a patch if helpful.



Discussion:
Interesting. I'm surprised it is touching histograms. This can be fixed.

I've never seen fill style 101 though. They should either be 0 or four digits right?

I'm using GEANT4's analysis manager, which outputs in several formats, including ROOT. This is the default setting, I don't think (due to it wrapping several output formats) that it can be changed even if I wanted a different fill style.

Agreed about the value, though, I don't see it listed in the fill styles on ROOT's docs. 

Yeah, I think I can fix this so rootpy doesn't care. Anyway, you're right that in root2hdf5 it should not even care about histograms. I think this is all an unintentional side effect of #673 


Resolving patch:
diff --git a/rootpy/info.py b/rootpy/info.py
--- a/rootpy/info.py
+++ b/rootpy/info.py
@@ -9,7 +9,7 @@
                     |_|    |___/
       {0}
 """
-__version__ = '0.8.1.dev0'
+__version__ = '0.8.2.dev0'
 __url__ = 'http://rootpy.github.com/rootpy'
 __repo_url__ = 'https://github.com/rootpy/rootpy/'
 __download_url__ = ('http://pypi.python.org/packages/source/r/'
diff --git a/rootpy/io/file.py b/rootpy/io/file.py
--- a/rootpy/io/file.py
+++ b/rootpy/io/file.py
@@ -581,7 +581,8 @@ def walk(self,
                 dirnames.append(name)
             if not is_directory or treat_dirs_as_objs:
                 if class_ref is not None:
-                    if not isinstance(tdirectory.Get(name), class_ref):
+                    tclass = ROOT.TClass.GetClass(classname, True, True)
+                    if not tclass or not tclass.InheritsFrom(class_ref.Class()):
                         continue
                 if class_pattern is not None:
                     if not fnmatch(classname, class_pattern):
diff --git a/rootpy/root2hdf5.py b/rootpy/root2hdf5.py
--- a/rootpy/root2hdf5.py
+++ b/rootpy/root2hdf5.py
@@ -9,16 +9,16 @@
 import os
 import sys
 import warnings
-import pkg_resources
+from pkg_resources import parse_version
 
 import tables
-TABLES_NEW_API = int(pkg_resources.parse_version(tables.__version__)[0]) >= 3
+TABLES_NEW_API = parse_version(tables.__version__) >= parse_version('3')
 if TABLES_NEW_API:
     tables_open = tables.open_file
 else:
     tables_open = tables.openFile
 
-from root_numpy import tree2rec, RootNumpyUnconvertibleWarning
+from root_numpy import tree2array, RootNumpyUnconvertibleWarning
 from numpy.lib import recfunctions
 
 from .io import root_open, TemporaryFile
@@ -125,16 +125,16 @@ def tree2hdf5(tree, hfile, group=None,
         # read the entire tree
         if pbar is not None:
             pbar.start()
-        recarray = tree2rec(tree, selection=selection)
-        recarray = _drop_object_col(recarray)
+        array = tree2array(tree, selection=selection)
+        array = _drop_object_col(array)
         if TABLES_NEW_API:
             table = hfile.create_table(
                 group, tree.GetName(),
-                recarray, tree.GetTitle())
+                array, tree.GetTitle())
         else:
             table = hfile.createTable(
                 group, tree.GetName(),
-                recarray, tree.GetTitle())
+                array, tree.GetTitle())
         # flush data in the table
         table.flush()
         # flush all pending data
@@ -151,31 +151,31 @@ def tree2hdf5(tree, hfile, group=None,
                     warnings.simplefilter(
                         "ignore",
                         tables.NaturalNameWarning)
-                    recarray = tree2rec(
+                    array = tree2array(
                         tree,
                         selection=selection,
                         start=start,
                         stop=start + entries)
-                recarray = _drop_object_col(recarray, warn=False)
-                table.append(recarray)
+                array = _drop_object_col(array, warn=False)
+                table.append(array)
             else:
-                recarray = tree2rec(
+                array = tree2array(
                     tree,
                     selection=selection,
                     start=start,
                     stop=start + entries)
-                recarray = _drop_object_col(recarray)
+                array = _drop_object_col(array)
                 if pbar is not None:
                     # start after any output from root_numpy
                     pbar.start()
                 if TABLES_NEW_API:
                     table = hfile.create_table(
                         group, tree.GetName(),
-                        recarray, tree.GetTitle())
+                        array, tree.GetTitle())
                 else:
                     table = hfile.createTable(
                         group, tree.GetName(),
-                        recarray, tree.GetTitle())
+                        array, tree.GetTitle())
             start += entries
             if start <= total_entries and pbar is not None:
                 pbar.update(start)


Test patch:
diff --git a/rootpy/tests/test_root2hdf5.py b/rootpy/tests/test_root2hdf5.py
--- a/rootpy/tests/test_root2hdf5.py
+++ b/rootpy/tests/test_root2hdf5.py
@@ -14,19 +14,16 @@
 
 
 def setup_func():
-
     global TEMPDIR
     TEMPDIR = mkdtemp()
 
 
 def teardown_func():
-
     shutil.rmtree(TEMPDIR)
 
 
 @with_setup(setup_func, teardown_func)
 def test_root2hdf5():
-
     try:
         import tables
     except ImportError:
@@ -45,7 +42,6 @@ def test_root2hdf5():
 
 @with_setup(setup_func, teardown_func)
 def test_root2hdf5_chunked():
-
     try:
         import tables
     except ImportError:
@@ -64,7 +60,6 @@ def test_root2hdf5_chunked():
 
 @with_setup(setup_func, teardown_func)
 def test_root2hdf5_chunked_selected():
-
     try:
         import tables
     except ImportError: