Skip to content

Commit 150eddf

Browse files
topper-123jreback
authored andcommitted
CLN: remove compat.add_metaclass (#26165)
1 parent 966d09e commit 150eddf

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

pandas/compat/__init__.py

-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
Key items to import for compatible code:
88
* lists: lrange(), lmap(), lzip()
9-
* add_metaclass(metaclass) - class decorator that recreates class with with the
10-
given metaclass instead (and avoids intermediary class creation)
119
1210
Other items:
1311
* platform checker
@@ -66,20 +64,6 @@ def set_function_name(f, name, cls):
6664
return f
6765

6866

69-
def add_metaclass(metaclass):
70-
"""
71-
Class decorator for creating a class with a metaclass.
72-
"""
73-
def wrapper(cls):
74-
orig_vars = cls.__dict__.copy()
75-
orig_vars.pop('__dict__', None)
76-
orig_vars.pop('__weakref__', None)
77-
for slots_var in orig_vars.get('__slots__', ()):
78-
orig_vars.pop(slots_var)
79-
return metaclass(cls.__name__, cls.__bases__, orig_vars)
80-
return wrapper
81-
82-
8367
def raise_with_traceback(exc, traceback=Ellipsis):
8468
"""
8569
Raise exception with existing traceback.

pandas/io/excel/_base.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pandas._config import config
99

1010
import pandas.compat as compat
11-
from pandas.compat import add_metaclass
1211
from pandas.errors import EmptyDataError
1312
from pandas.util._decorators import Appender, deprecate_kwarg
1413

@@ -328,8 +327,7 @@ def read_excel(io,
328327
**kwds)
329328

330329

331-
@add_metaclass(abc.ABCMeta)
332-
class _BaseExcelReader:
330+
class _BaseExcelReader(metaclass=abc.ABCMeta):
333331

334332
@property
335333
@abc.abstractmethod
@@ -487,8 +485,7 @@ def parse(self,
487485
return output[asheetname]
488486

489487

490-
@add_metaclass(abc.ABCMeta)
491-
class ExcelWriter:
488+
class ExcelWriter(metaclass=abc.ABCMeta):
492489
"""
493490
Class for writing DataFrame objects into excel sheets, default is to use
494491
xlwt for xls, openpyxl for xlsx. See DataFrame.to_excel for typical usage.

pandas/tseries/holiday.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dateutil.relativedelta import FR, MO, SA, SU, TH, TU, WE # noqa
66
import numpy as np
77

8-
from pandas.compat import add_metaclass
98
from pandas.errors import PerformanceWarning
109

1110
from pandas import DateOffset, Series, Timestamp, date_range
@@ -324,12 +323,10 @@ def __new__(cls, clsname, bases, attrs):
324323
return calendar_class
325324

326325

327-
@add_metaclass(HolidayCalendarMetaClass)
328-
class AbstractHolidayCalendar:
326+
class AbstractHolidayCalendar(metaclass=HolidayCalendarMetaClass):
329327
"""
330328
Abstract interface to create holidays following certain rules.
331329
"""
332-
__metaclass__ = HolidayCalendarMetaClass
333330
rules = [] # type: List[Holiday]
334331
start_date = Timestamp(datetime(1970, 1, 1))
335332
end_date = Timestamp(datetime(2030, 12, 31))

0 commit comments

Comments
 (0)