@@ -196,6 +196,48 @@ def timestampFormat(self, timestampFormat):
196196 #assert isinstance(timestampFormat, unicode) or timestampFormat.__class__.__name__ == "DateFormat", "not of type unicode"
197197 self ._timestampFormat = timestampFormat
198198
199+ def rename (self , index = None , columns = None , ** kwargs ):
200+ """
201+ Renames the dataframe inplace calling appropriate signals.
202+ Wraps pandas.DataFrame.rename(*args, **kwargs) - overrides
203+ the inplace kwarg setting it to True.
204+
205+ Example use:
206+ renames = {'colname1':'COLNAME_1', 'colname2':'COL2'}
207+ DataFrameModel.rename(columns=renames)
208+
209+ :param args:
210+ see pandas.DataFrame.rename
211+ :param kwargs:
212+ see pandas.DataFrame.rename
213+ :return:
214+ True on success, False on failure.
215+ """
216+ kwargs ['inplace' ] = True
217+ self .layoutAboutToBeChanged .emit ()
218+ self ._dataFrame .rename (index , columns , ** kwargs )
219+ self .layoutChanged .emit ()
220+ self .dataChanged .emit ()
221+ self .dataFrameChanged .emit ()
222+
223+ def applyFunction (self , func ):
224+ """
225+ Applies a function to the dataFrame with appropriate signals.
226+ :param func: A function (or partial function) that accepts a dataframe as the first argument.
227+ :return: None
228+ :raise:
229+ AssertionError if the func is not callable.
230+ AssertionError if the func does not return a DataFrame.
231+ """
232+ assert callable (func ), "function {} is not callable" .format (func )
233+ self .layoutAboutToBeChanged .emit ()
234+ df = func (self ._dataFrame )
235+ assert isinstance (df , pandas .DataFrame ), "method {} did not return a DataFrame." .format (func .__name__ )
236+ self ._dataFrame = df
237+ self .layoutChanged .emit ()
238+ self .dataChanged .emit ()
239+ self .dataFrameChanged .emit ()
240+
199241 def headerData (self , section , orientation , role = Qt .DisplayRole ):
200242 """
201243 Return the header depending on section, orientation and Qt::ItemDataRole
0 commit comments