liac-arff
raw JSON → 2.5.0 verified Fri May 01 auth: no python
liac-arff is a Python library for reading and writing ARFF (Attribute-Relation File Format) files, commonly used in WEKA machine learning toolkits. Current version 2.5.0 is the last to support Python 2. It supports sparse ARFF, data generators, and standard Java escape sequences. Release cadence is irregular, with about 1-2 releases per year.
pip install liac-arff Common errors
error AttributeError: module 'arff' has no attribute 'load' ↓
cause Attempting to import 'load' directly from arff (e.g., `from arff import load`) but the correct usage is to import the module and call arff.load.
fix
Use
import arff then data = arff.load(...) error TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader ↓
cause Passing an open file handle where a path string is expected (often from mixing with other libraries).
fix
Ensure you pass the file object to
arff.load(), not the path. If a path is needed, open it first: with open(path) as f: arff.load(f) Warnings
gotcha The `load()` function expects a file-like object, not a file path. Use `open()` or `io.StringIO`. ↓
fix Use `with open('file.arff') as f: data = arff.load(f)`
gotcha When using `return_type='generator'`, the returned object is a generator that yields rows incrementally, but the `attributes` key is only available after the first iteration or after exhausting the generator. Accessing `data['attributes']` before iterating may raise an error or return an empty list. ↓
fix Iterate over the generator first or use `list(data['data'])` to consume it, then access `data['attributes']`.
breaking Python 2.7 support removed in version 2.5.0. Users on Python 2 must stay on version 2.4.0 or earlier. ↓
fix Upgrade to Python 3.5+ or pin liac-arff to <=2.4.0.
Imports
- arff
import arff - load wrong
from arff import loadcorrectdata = arff.load(open('file.arff'))
Quickstart
import arff
# Load ARFF file
with open('example.arff') as f:
data = arff.load(f)
print(data['attributes'])
print(data['data'])
# Load with generator (lazy loading)
with open('example.arff') as f:
for row in arff.load(f, return_type='generator'):
print(row)