Skip to content

Commit 926991d

Browse files
committed
ENH: Added PySide support for qtpandas.
1 parent 6857482 commit 926991d

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Experimental Features
7777
(:issue:`4897`).
7878
- Add msgpack support via ``pd.read_msgpack()`` and ``pd.to_msgpack()`` / ``df.to_msgpack()`` for serialization
7979
of arbitrary pandas (and python objects) in a lightweight portable binary format (:issue:`686`)
80+
- Added PySide support for the qtpandas DataFrameModel and DataFrameWidget.
8081

8182
Improvements to existing features
8283
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/source/v0.13.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ Experimental
600600

601601
os.remove('foo.msg')
602602

603+
- Added PySide support for the qtpandas DataFrameModel and DataFrameWidget.
604+
603605
.. _whatsnew_0130.refactoring:
604606

605607
Internal Refactoring

pandas/sandbox/qtpandas.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
44
@author: Jev Kuznetsov
55
'''
6-
from PyQt4.QtCore import (
7-
QAbstractTableModel, Qt, QVariant, QModelIndex, SIGNAL)
8-
from PyQt4.QtGui import (
9-
QApplication, QDialog, QVBoxLayout, QTableView, QWidget)
6+
try:
7+
from PyQt4.QtCore import QAbstractTableModel, Qt, QVariant, QModelIndex
8+
from PyQt4.QtGui import (
9+
QApplication, QDialog, QVBoxLayout, QTableView, QWidget)
10+
except ImportError:
11+
from PySide.QtCore import QAbstractTableModel, Qt, QModelIndex
12+
from PySide.QtGui import (
13+
QApplication, QDialog, QVBoxLayout, QTableView, QWidget)
14+
QVariant = lambda value=None: value
1015

1116
from pandas import DataFrame, Index
1217

@@ -57,9 +62,17 @@ def flags(self, index):
5762
return flags
5863

5964
def setData(self, index, value, role):
60-
self.df.set_value(self.df.index[index.row()],
61-
self.df.columns[index.column()],
62-
value.toPyObject())
65+
row = self.df.index[index.row()]
66+
col = self.df.columns[index.column()]
67+
if hasattr(value, 'toPyObject'):
68+
# PyQt4 gets a QVariant
69+
value = value.toPyObject()
70+
else:
71+
# PySide gets an unicode
72+
dtype = self.df[col].dtype
73+
if dtype != object:
74+
value = None if value == '' else dtype.type(value)
75+
self.df.set_value(row, col, value)
6376
return True
6477

6578
def rowCount(self, index=QModelIndex()):

0 commit comments

Comments
 (0)