99
1010import csv as csvlib
1111from zipfile import ZipFile
12+
1213import numpy as np
1314
14- from pandas .core . dtypes . missing import notna
15- from pandas . core . index import Index , MultiIndex
15+ from pandas ._libs import writers as libwriters
16+
1617from pandas import compat
17- from pandas .compat import (StringIO , range , zip )
18+ from pandas .compat import StringIO , range , zip
19+
20+ from pandas .core .dtypes .missing import notna
21+ from pandas .core .dtypes .generic import (
22+ ABCMultiIndex , ABCPeriodIndex , ABCDatetimeIndex , ABCIndexClass )
1823
1924from pandas .io .common import (_get_handle , UnicodeWriter , _expand_user ,
2025 _stringify_path )
21- from pandas ._libs import writers as libwriters
22- from pandas .core .indexes .datetimes import DatetimeIndex
23- from pandas .core .indexes .period import PeriodIndex
2426
2527
2628class CSVFormatter (object ):
@@ -68,7 +70,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
6870 self .date_format = date_format
6971
7072 self .tupleize_cols = tupleize_cols
71- self .has_mi_columns = (isinstance (obj .columns , MultiIndex ) and
73+ self .has_mi_columns = (isinstance (obj .columns , ABCMultiIndex ) and
7274 not self .tupleize_cols )
7375
7476 # validate mi options
@@ -78,7 +80,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
7880 "columns" )
7981
8082 if cols is not None :
81- if isinstance (cols , Index ):
83+ if isinstance (cols , ABCIndexClass ):
8284 cols = cols .to_native_types (na_rep = na_rep ,
8385 float_format = float_format ,
8486 date_format = date_format ,
@@ -90,7 +92,7 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
9092 # update columns to include possible multiplicity of dupes
9193 # and make sure sure cols is just a list of labels
9294 cols = self .obj .columns
93- if isinstance (cols , Index ):
95+ if isinstance (cols , ABCIndexClass ):
9496 cols = cols .to_native_types (na_rep = na_rep ,
9597 float_format = float_format ,
9698 date_format = date_format ,
@@ -111,8 +113,9 @@ def __init__(self, obj, path_or_buf=None, sep=",", na_rep='',
111113 self .chunksize = int (chunksize )
112114
113115 self .data_index = obj .index
114- if (isinstance (self .data_index , (DatetimeIndex , PeriodIndex )) and
116+ if (isinstance (self .data_index , (ABCDatetimeIndex , ABCPeriodIndex )) and
115117 date_format is not None ):
118+ from pandas import Index
116119 self .data_index = Index ([x .strftime (date_format ) if notna (x ) else
117120 '' for x in self .data_index ])
118121
@@ -197,7 +200,8 @@ def _save_header(self):
197200 header = self .header
198201 encoded_labels = []
199202
200- has_aliases = isinstance (header , (tuple , list , np .ndarray , Index ))
203+ has_aliases = isinstance (header , (tuple , list , np .ndarray ,
204+ ABCIndexClass ))
201205 if not (has_aliases or self .header ):
202206 return
203207 if has_aliases :
@@ -214,7 +218,7 @@ def _save_header(self):
214218 # should write something for index label
215219 if index_label is not False :
216220 if index_label is None :
217- if isinstance (obj .index , MultiIndex ):
221+ if isinstance (obj .index , ABCMultiIndex ):
218222 index_label = []
219223 for i , name in enumerate (obj .index .names ):
220224 if name is None :
@@ -227,7 +231,7 @@ def _save_header(self):
227231 else :
228232 index_label = [index_label ]
229233 elif not isinstance (index_label ,
230- (list , tuple , np .ndarray , Index )):
234+ (list , tuple , np .ndarray , ABCIndexClass )):
231235 # given a string for a DF with Index
232236 index_label = [index_label ]
233237
0 commit comments