# Path: kquant_data/utils/xdatetime.py
# def yyyyMMddHHmm_2_datetime(dt):
#     """
#     输入一个长整型yyyyMMddhmm，返回对应的时间
#     :param dt:
#     :return:
#     """
#     dt = int(dt)  # FIXME：在python2下会有问题吗？
#     (yyyyMMdd, hh) = divmod(dt, 10000)
#     (yyyy, MMdd) = divmod(yyyyMMdd, 10000)
#     (MM, dd) = divmod(MMdd, 100)
#     (hh, mm) = divmod(hh, 100)
# 
#     return datetime(yyyy, MM, dd, hh, mm)
# 
# def datetime_2_yyyyMMddHHmm(dt):
#     """
#     将时间转换成float类型
#     :param dt:
#     :return:
#     """
#     t = dt.timetuple()
#     return float((t.tm_year * 10000.0 + t.tm_mon * 100 + t.tm_mday) * 10000.0) + t.tm_hour * 100 + t.tm_min
# 
# def tic():
#     """
#     对应MATLAB中的tic
#     :return:
#     """
#     globals()['tt'] = time.clock()
# 
# def toc():
#     """
#     对应MATLAB中的toc
#     :return:
#     """
#     t = time.clock() - globals()['tt']
#     print('\nElapsed time: %.8f seconds\n' % t)
#     return t
# 
# Path: kquant_data/xio/csv.py
# def read_data_dataframe(path, sep=','):
#     """
#     读取季报的公告日
#     注意：有些股票多个季度一起发，一般是公司出问题了，特别是600878，四个报告同一天发布
#     年报与一季报很有可能一起发
#     :param path:
#     :param sep:
#     :return:
#     """
#     try:
#         df = pd.read_csv(path, index_col=0, parse_dates=True, encoding='utf-8-sig', sep=sep)
#     except (FileNotFoundError, OSError):
#         return None
# 
#     return df


import os
import datetime
import numpy as np
import pandas as pd
import multiprocessing
from functools import partial
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime, datetime_2_yyyyMMddHHmm, tic, toc
from ..xio.csv import read_data_dataframe
        rolling_count.count += 1
    else:
        rolling_count.previous = val
        rolling_count.count = 0
    return rolling_count.count


rolling_count.count = 0  # static variable
rolling_count.previous = None  # static variable


def series_drop_duplicated_keep_both_rolling(series):
    """
    删除重复，只保留前后两端的数据
    如果中间出现重复数据也能使用了
    :param series:
    :return:
    """
    rolling_count.previous = None
    _count_ = series.apply(rolling_count)
    _first_ = _count_ == 0
    _last_ = _first_.shift(-1)
    _last_[-1] = True

    series = series[_first_ | _last_]
    return series


def filter_dataframe(df, index_name=None, start_date=None, end_date=None, fields=None):
    if index_name is not None:

# Path: kquant_data/utils/xdatetime.py
# def yyyyMMddHHmm_2_datetime(dt):
#     """
#     输入一个长整型yyyyMMddhmm，返回对应的时间
#     :param dt:
#     :return:
#     """
#     dt = int(dt)  # FIXME：在python2下会有问题吗？
#     (yyyyMMdd, hh) = divmod(dt, 10000)
#     (yyyy, MMdd) = divmod(yyyyMMdd, 10000)
#     (MM, dd) = divmod(MMdd, 100)
#     (hh, mm) = divmod(hh, 100)
# 
#     return datetime(yyyy, MM, dd, hh, mm)
# 
# def datetime_2_yyyyMMddHHmm(dt):
#     """
#     将时间转换成float类型
#     :param dt:
#     :return:
#     """
#     t = dt.timetuple()
#     return float((t.tm_year * 10000.0 + t.tm_mon * 100 + t.tm_mday) * 10000.0) + t.tm_hour * 100 + t.tm_min
# 
# def tic():
#     """
#     对应MATLAB中的tic
#     :return:
#     """
#     globals()['tt'] = time.clock()
# 
# def toc():
#     """
#     对应MATLAB中的toc
#     :return:
#     """
#     t = time.clock() - globals()['tt']
#     print('\nElapsed time: %.8f seconds\n' % t)
#     return t
# 
# Path: kquant_data/xio/csv.py
# def read_data_dataframe(path, sep=','):
#     """
#     读取季报的公告日
#     注意：有些股票多个季度一起发，一般是公司出问题了，特别是600878，四个报告同一天发布
#     年报与一季报很有可能一起发
#     :param path:
#     :param sep:
#     :return:
#     """
#     try:
#         df = pd.read_csv(path, index_col=0, parse_dates=True, encoding='utf-8-sig', sep=sep)
#     except (FileNotFoundError, OSError):
#         return None
# 
#     return df


# Path: kquant_data/processing/utils.py
import os
import datetime
import numpy as np
import pandas as pd
import multiprocessing
from functools import partial
from ..utils.xdatetime import yyyyMMddHHmm_2_datetime, datetime_2_yyyyMMddHHmm, tic, toc
from ..xio.csv import read_data_dataframe

        rolling_count.count += 1
    else:
        rolling_count.previous = val
        rolling_count.count = 0
    return rolling_count.count


rolling_count.count = 0  # static variable
rolling_count.previous = None  # static variable


def series_drop_duplicated_keep_both_rolling(series):
    """
    删除重复，只保留前后两端的数据
    如果中间出现重复数据也能使用了
    :param series:
    :return:
    """
    rolling_count.previous = None
    _count_ = series.apply(rolling_count)
    _first_ = _count_ == 0
    _last_ = _first_.shift(-1)
    _last_[-1] = True

    series = series[_first_ | _last_]
    return series


def filter_dataframe(df, index_name=None, start_date=None, end_date=None, fields=None):
    if index_name is not None:

        df['index_datetime'] = df[index_name].apply(yyyyMMddHHmm_2_datetime)