From a2aa06999818f2ccecff35d74012193178e2dab4 Mon Sep 17 00:00:00 2001 From: Prajjwal Nijhara Date: Tue, 28 Apr 2020 01:01:14 +0530 Subject: [PATCH 1/2] Fix some code quality and bug-risk issues --- .deepsource.toml | 15 +++++++++++++++ gs_quant/api/fred/data.py | 2 +- gs_quant/api/gs/content.py | 4 +++- gs_quant/target/backtests.py | 6 ++++-- gs_quant/timeseries/measures.py | 4 ++-- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 00000000..62c7209a --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,15 @@ +version = 1 + +test_patterns = ["*/test/**"] + +exclude_patterns = [ + "*/data/**", + "*/examples/**" +] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" \ No newline at end of file diff --git a/gs_quant/api/fred/data.py b/gs_quant/api/fred/data.py index 40759861..cdcb722b 100644 --- a/gs_quant/api/fred/data.py +++ b/gs_quant/api/fred/data.py @@ -137,7 +137,7 @@ def construct_dataframe_with_types(self, dataset_id: str, data: pd.Series) -> pd :param data: Data to convert with correct types :return: Dataframe with correct types """ - if len(data) and isinstance(data, pd.Series): + if data and isinstance(data, pd.Series): return data.to_frame() else: return pd.DataFrame({}) diff --git a/gs_quant/api/gs/content.py b/gs_quant/api/gs/content.py index f18c2adb..07312456 100644 --- a/gs_quant/api/gs/content.py +++ b/gs_quant/api/gs/content.py @@ -47,7 +47,7 @@ def get_contents( tags: set = None, offset: int = 0, limit: int = 10, - order_by: dict = {'direction': OrderBy.DESC, 'field': 'createdTime'} + order_by: dict = None ) -> List[ContentResponse]: """ Get contents for given parameters @@ -69,6 +69,8 @@ def get_contents( >>> GsSession.use() >>> contents = GsContentApi.get_contents(channels=['G10']) """ + if order_by is None: + order_by = {'direction': OrderBy.DESC, 'field': 'createdTime'} if limit and limit > 1000: raise ValueError('Limit is too large. Limit must be <= 1000.') diff --git a/gs_quant/target/backtests.py b/gs_quant/target/backtests.py index e6457926..0da1b060 100644 --- a/gs_quant/target/backtests.py +++ b/gs_quant/target/backtests.py @@ -2490,9 +2490,11 @@ def __init__( trading_parameters: BacktestTradingParameters, index_initial_value: float, underliers: Tuple[BacktestStrategyUnderlier, ...] = None, - measures: Tuple[Union[FlowVolBacktestMeasure, str], ...] = ['ALL MEASURES'], + measures: Tuple[Union[FlowVolBacktestMeasure, str], ...] = None, name: str = None - ): + ): + if measures is None: + measures = ['ALL MEASURES'] super().__init__() self.index_initial_value = index_initial_value self.underliers = underliers diff --git a/gs_quant/timeseries/measures.py b/gs_quant/timeseries/measures.py index 236412bd..c7c7b62d 100644 --- a/gs_quant/timeseries/measures.py +++ b/gs_quant/timeseries/measures.py @@ -314,7 +314,7 @@ def convert_asset_for_rates_data_set(from_asset: Asset, c_type: RatesConversionT return GsAssetApi.map_identifiers(GsIdType.mdapi, GsIdType.id, [to_asset])[to_asset] except KeyError: - logging.info(f'Unsupported currency or cross') + logging.info('Unsupported currency or cross') return from_asset.get_marquee_id() @@ -1184,7 +1184,7 @@ def vol_term(asset: Asset, strike_reference: VolReference, relative_strike: Real if strike_reference == VolReference.NORMALIZED: raise MqValueError(f'strike reference {strike_reference} not supported for FX') if strike_reference == VolReference.DELTA_NEUTRAL and relative_strike != 0: - raise MqValueError(f'relative_strike must be 0 for delta_neutral') + raise MqValueError('relative_strike must be 0 for delta_neutral') if strike_reference == VolReference.DELTA_PUT: relative_strike *= -1 From 77ad96399b93c75b8b37bb15b68db7208d6a3880 Mon Sep 17 00:00:00 2001 From: Prajjwal Nijhara Date: Tue, 28 Apr 2020 01:34:08 +0530 Subject: [PATCH 2/2] Add dco/Prajjwal Nijhara.dco --- dco/Prajjwal Nijhara.dco | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 dco/Prajjwal Nijhara.dco diff --git a/dco/Prajjwal Nijhara.dco b/dco/Prajjwal Nijhara.dco new file mode 100644 index 00000000..dc58e904 --- /dev/null +++ b/dco/Prajjwal Nijhara.dco @@ -0,0 +1,9 @@ +1) I, Prajjwal Nijhara, certify that all work committed with the commit message +"covered by: Prajjwal Nijhara.dco" is my original work and I own the copyright +to this work. I agree to contribute this code under the Apache 2.0 license. + +2) I understand and agree all contribution including all personal +information I submit with it is maintained indefinitely and may be +redistributed consistent with the open source license(s) involved. + +This certification is effective for all code contributed from 2020-04-28 to 9999-01-01.