CityLearn 2.3.0__tar.gz → 2.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/PKG-INFO +1 -1
  2. {CityLearn-2.3.0 → CityLearn-2.3.1}/PKG-INFO +1 -1
  3. CityLearn-2.3.1/citylearn/__init__.py +1 -0
  4. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/__main__.py +5 -5
  5. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/citylearn.py +3 -3
  6. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/data.py +14 -14
  7. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/neighborhood.py +3 -3
  8. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/occupant.py +3 -3
  9. CityLearn-2.3.1/citylearn/utilities.py +145 -0
  10. CityLearn-2.3.0/citylearn/__init__.py +0 -1
  11. CityLearn-2.3.0/citylearn/utilities.py +0 -138
  12. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/SOURCES.txt +0 -0
  13. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/dependency_links.txt +0 -0
  14. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/entry_points.txt +0 -0
  15. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/requires.txt +0 -0
  16. {CityLearn-2.3.0 → CityLearn-2.3.1}/CityLearn.egg-info/top_level.txt +0 -0
  17. {CityLearn-2.3.0 → CityLearn-2.3.1}/LICENSE +0 -0
  18. {CityLearn-2.3.0 → CityLearn-2.3.1}/MANIFEST.in +0 -0
  19. {CityLearn-2.3.0 → CityLearn-2.3.1}/README.md +0 -0
  20. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/__init__.py +0 -0
  21. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/base.py +0 -0
  22. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/marlisa.py +0 -0
  23. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/q_learning.py +0 -0
  24. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/rbc.py +0 -0
  25. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/rlc.py +0 -0
  26. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/agents/sac.py +0 -0
  27. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-0-charge-0.png +0 -0
  28. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-0-charge-1.png +0 -0
  29. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-0-charge-2.png +0 -0
  30. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-0-charge-3.png +0 -0
  31. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-1-charge-0.png +0 -0
  32. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-1-charge-1.png +0 -0
  33. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-1-charge-2.png +0 -0
  34. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/building-1-charge-3.png +0 -0
  35. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/glow.png +0 -0
  36. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/assets/grid.png +0 -0
  37. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/base.py +0 -0
  38. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/building.py +0 -0
  39. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/cost_function.py +0 -0
  40. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/dynamics.py +0 -0
  41. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/electric_vehicle.py +0 -0
  42. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/electric_vehicle_charger.py +0 -0
  43. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/__init__.py +0 -0
  44. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/clustering.py +0 -0
  45. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/lstm_model/__init__.py +0 -0
  46. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/lstm_model/model.py +0 -0
  47. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/lstm_model/model_generation.py +0 -0
  48. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/lstm_model/model_generation_wrapper.py +0 -0
  49. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/lstm_model/preprocessing.py +0 -0
  50. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/end_use_load_profiles/simulate.py +0 -0
  51. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/energy_model.py +0 -0
  52. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/create_zone_metadata.sql +0 -0
  53. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/select_citylearn_energy_simulation.sql +0 -0
  54. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/select_citylearn_weather.sql +0 -0
  55. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/select_ideal_loads.sql +0 -0
  56. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/select_lstm_training_data.sql +0 -0
  57. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/queries/select_zone_conditioning_metadata.sql +0 -0
  58. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/misc/settings.yaml +0 -0
  59. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/power_outage.py +0 -0
  60. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/preprocessing.py +0 -0
  61. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/reward_function.py +0 -0
  62. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/rl.py +0 -0
  63. {CityLearn-2.3.0 → CityLearn-2.3.1}/citylearn/wrappers.py +0 -0
  64. {CityLearn-2.3.0 → CityLearn-2.3.1}/setup.cfg +0 -0
  65. {CityLearn-2.3.0 → CityLearn-2.3.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CityLearn
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: An open source Farama Foundation Gymnasium environment for benchmarking distributed energy resource control algorithms to provide energy flexibility in a district of buildings.
5
5
  Home-page: https://github.com/intelligent-environments-lab/CityLearn
6
6
  Author: Jose Ramon Vazquez-Canteli, Kingsley Nweye, Zoltan Nagy
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CityLearn
3
- Version: 2.3.0
3
+ Version: 2.3.1
4
4
  Summary: An open source Farama Foundation Gymnasium environment for benchmarking distributed energy resource control algorithms to provide energy flexibility in a district of buildings.
5
5
  Home-page: https://github.com/intelligent-environments-lab/CityLearn
6
6
  Author: Jose Ramon Vazquez-Canteli, Kingsley Nweye, Zoltan Nagy
@@ -0,0 +1 @@
1
+ __version__ = '2.3.1'
@@ -18,7 +18,7 @@ from citylearn.agents.base import Agent as CityLearnAgent
18
18
  from citylearn.citylearn import CityLearnEnv
19
19
  from citylearn.data import DataSet, get_settings
20
20
  from citylearn.__init__ import __version__
21
- from citylearn.utilities import read_pickle, write_json, write_pickle
21
+ from citylearn.utilities import FileHandler
22
22
  import pandas as pd
23
23
  import simplejson as json
24
24
 
@@ -291,7 +291,7 @@ class Simulator:
291
291
  def __save_agent(self):
292
292
  if isinstance(self.agent, CityLearnAgent):
293
293
  filepath = os.path.join(self.output_directory, f'{self.simulation_id}-agent.pkl')
294
- write_pickle(filepath, self.agent)
294
+ FileHandler.write_pickle(filepath, self.agent)
295
295
 
296
296
  else:
297
297
  filepath = os.path.join(self.output_directory, f'{self.simulation_id}-agent')
@@ -307,7 +307,7 @@ class Simulator:
307
307
 
308
308
  else:
309
309
  if str(self.agent_filepath).endswith('.pkl'):
310
- agent = read_pickle(self.agent_filepath)
310
+ agent = FileHandler.read_pickle(self.agent_filepath)
311
311
  agent.env = self.env
312
312
 
313
313
  else:
@@ -349,7 +349,7 @@ class Simulator:
349
349
  simulator = cls(**kwargs)
350
350
  simulator.__evaluate()
351
351
  filepath = os.path.join(simulator.output_directory, f'{simulator.simulation_id}-evaluation.json')
352
- write_json(filepath, simulator.__get_evaluation_summary())
352
+ FileHandler.write_json(filepath, simulator.__get_evaluation_summary())
353
353
 
354
354
  @classmethod
355
355
  def train(cls, episodes: int = None, evaluate: bool = None, evaluation_episode_time_steps: Tuple[int, int] = None, save_agent: bool = None, **kwargs):
@@ -357,7 +357,7 @@ class Simulator:
357
357
  episodes = 1 if episodes is None else episodes
358
358
  simulator.__train(episodes)
359
359
  filepath = os.path.join(simulator.output_directory, f'{simulator.simulation_id}-train.json')
360
- write_json(filepath, simulator.__get_training_summary())
360
+ FileHandler.write_json(filepath, simulator.__get_training_summary())
361
361
 
362
362
  if save_agent:
363
363
  simulator.__save_agent()
@@ -12,11 +12,11 @@ import pandas as pd
12
12
  from citylearn.base import Environment, EpisodeTracker
13
13
  from citylearn.building import Building, DynamicsBuilding
14
14
  from citylearn.cost_function import CostFunction
15
- from citylearn.data import CarbonIntensity, DataSet, ElectricVehicleSimulation, EnergySimulation, LogisticRegressionOccupantParameters, Pricing, TOLERANCE, Weather
15
+ from citylearn.data import CarbonIntensity, DataSet, ElectricVehicleSimulation, EnergySimulation, LogisticRegressionOccupantParameters, Pricing, Weather
16
16
  from citylearn.electric_vehicle import ElectricVehicle
17
17
  from citylearn.energy_model import Battery, PV
18
18
  from citylearn.reward_function import RewardFunction
19
- from citylearn.utilities import read_json
19
+ from citylearn.utilities import FileHandler
20
20
 
21
21
  LOGGER = logging.getLogger()
22
22
  logging.getLogger('matplotlib.font_manager').disabled = True
@@ -751,7 +751,7 @@ class CityLearnEnv(Environment, Env):
751
751
 
752
752
  if isinstance(schema, (str, Path)) and os.path.isfile(schema):
753
753
  schema_filepath = Path(schema) if isinstance(schema, str) else schema
754
- schema = read_json(schema)
754
+ schema = FileHandler.read_json(schema)
755
755
  schema['root_directory'] = os.path.split(schema_filepath.absolute())[0] if schema['root_directory'] is None \
756
756
  else schema['root_directory']
757
757
 
@@ -10,7 +10,7 @@ import requests
10
10
  from requests.adapters import HTTPAdapter
11
11
  from urllib3.util.retry import Retry
12
12
  from citylearn.__init__ import __version__
13
- from citylearn.utilities import join_url, read_json, read_yaml, write_json
13
+ from citylearn.utilities import FileHandler
14
14
 
15
15
  LOGGER = logging.getLogger()
16
16
  logging.basicConfig(level=logging.INFO)
@@ -24,7 +24,7 @@ SETTINGS_FILEPATH = os.path.join(MISC_DIRECTORY, 'settings.yaml')
24
24
  def get_settings():
25
25
  directory = os.path.join(os.path.join(os.path.dirname(__file__), 'misc'))
26
26
  filepath = os.path.join(directory, 'settings.yaml')
27
- settings = read_yaml(filepath)
27
+ settings = FileHandler.read_yaml(filepath)
28
28
 
29
29
  return settings
30
30
 
@@ -34,10 +34,10 @@ class DataSet:
34
34
  GITHUB_ACCOUNT = 'intelligent-environments-lab'
35
35
  REPOSITORY_NAME = 'CityLearn'
36
36
  REPOSITORY_TAG = f'v{__version__}'
37
- REPOSITORY_DATA_PATH = join_url('data')
38
- REPOSITORY_DATA_DATASETS_PATH = join_url(REPOSITORY_DATA_PATH, 'datasets')
39
- REPOSITORY_DATA_MISC_PATH = join_url(REPOSITORY_DATA_PATH, 'misc')
40
- GITHUB_API_CONTENT_URL = join_url('https://api.github.com/repos/', GITHUB_ACCOUNT, REPOSITORY_NAME, 'contents')
37
+ REPOSITORY_DATA_PATH = FileHandler.join_url('data')
38
+ REPOSITORY_DATA_DATASETS_PATH = FileHandler.join_url(REPOSITORY_DATA_PATH, 'datasets')
39
+ REPOSITORY_DATA_MISC_PATH = FileHandler.join_url(REPOSITORY_DATA_PATH, 'misc')
40
+ GITHUB_API_CONTENT_URL = FileHandler.join_url('https://api.github.com/repos/', GITHUB_ACCOUNT, REPOSITORY_NAME, 'contents')
41
41
  DEFAULT_CACHE_DIRECTORY = os.path.join(user_cache_dir('citylearn'), REPOSITORY_TAG)
42
42
  BATTERY_CHOICES_FILENAME = 'battery_choices.yaml'
43
43
  PV_CHOICES_FILENAME = 'lbl-tracking_the_sun-res-pv.csv'
@@ -112,7 +112,7 @@ class DataSet:
112
112
 
113
113
  def get_schema(self, name: str) -> dict:
114
114
  schema_filepath = self.get_dataset(name)
115
- schema = read_json(schema_filepath)
115
+ schema = FileHandler.read_json(schema_filepath)
116
116
  schema['root_directory'] = os.path.split(Path(schema_filepath).absolute())[0]
117
117
 
118
118
  return schema
@@ -121,7 +121,7 @@ class DataSet:
121
121
  datasets_directory = os.path.join(self.cache_directory, 'datasets')
122
122
  root_directory = os.path.join(datasets_directory, name)
123
123
  schema_filepath = os.path.join(root_directory, 'schema.json')
124
- path = join_url(self.datasets_path, name)
124
+ path = FileHandler.join_url(self.datasets_path, name)
125
125
 
126
126
  # check that dataset does not already exist using the schema as a proxy
127
127
  if not os.path.isfile(schema_filepath):
@@ -169,7 +169,7 @@ class DataSet:
169
169
  filepath = os.path.join(self.cache_directory, 'dataset_names.json')
170
170
 
171
171
  if os.path.isfile(filepath):
172
- contents = read_json(filepath)
172
+ contents = FileHandler.read_json(filepath)
173
173
 
174
174
  else:
175
175
  LOGGER.info(f'The dataset names DNE in cache. Will download from '
@@ -181,7 +181,7 @@ class DataSet:
181
181
  if r.get('type') == 'dir'
182
182
  and r.get('path').replace(r['name'], '').strip('/') == self.datasets_path
183
183
  ]
184
- write_json(filepath, contents)
184
+ FileHandler.write_json(filepath, contents)
185
185
 
186
186
  contents = sorted(contents)
187
187
 
@@ -198,7 +198,7 @@ class DataSet:
198
198
  misc_directory = os.path.join(self.cache_directory, 'misc')
199
199
  os.makedirs(misc_directory, exist_ok=True)
200
200
  filepath = os.path.join(misc_directory, self.PV_CHOICES_FILENAME)
201
- path = join_url(self.misc_path)
201
+ path = FileHandler.join_url(self.misc_path)
202
202
 
203
203
  # check that file DNE
204
204
  if not os.path.isfile(filepath):
@@ -231,7 +231,7 @@ class DataSet:
231
231
  misc_directory = os.path.join(self.cache_directory, 'misc')
232
232
  os.makedirs(misc_directory, exist_ok=True)
233
233
  filepath = os.path.join(misc_directory, self.BATTERY_CHOICES_FILENAME)
234
- path = join_url(self.misc_path)
234
+ path = FileHandler.join_url(self.misc_path)
235
235
 
236
236
  # check that file DNE
237
237
  if not os.path.isfile(filepath):
@@ -249,7 +249,7 @@ class DataSet:
249
249
  else:
250
250
  pass
251
251
 
252
- data = read_yaml(filepath)
252
+ data = FileHandler.read_yaml(filepath)
253
253
  data = pd.DataFrame([{'model': k, **v['attributes']} for k, v in data.items()])
254
254
  data = data.set_index('model')
255
255
 
@@ -263,7 +263,7 @@ class DataSet:
263
263
  pass
264
264
 
265
265
  def get_github_contents(self, path: str = None) -> List[Mapping[str, Any]]:
266
- url = self.GITHUB_API_CONTENT_URL if path is None else join_url(self.GITHUB_API_CONTENT_URL, path)
266
+ url = self.GITHUB_API_CONTENT_URL if path is None else FileHandler.join_url(self.GITHUB_API_CONTENT_URL, path)
267
267
  params = dict(ref=self.tag)
268
268
  contents = self.get_requests_session().get(url, params=params)
269
269
 
@@ -23,7 +23,7 @@ from citylearn.end_use_load_profiles.clustering import MetadataClustering
23
23
  from citylearn.end_use_load_profiles.lstm_model.model_generation_wrapper import run_one_model
24
24
  from citylearn.end_use_load_profiles.simulate import EndUseLoadProfilesEnergyPlusPartialLoadSimulator
25
25
  from citylearn.preprocessing import PeriodicNormalization, Normalize
26
- from citylearn.utilities import read_json, write_json
26
+ from citylearn.utilities import FileHandler
27
27
 
28
28
  BuildingSimulators = Mapping[
29
29
  str,
@@ -255,7 +255,7 @@ class Neighborhood:
255
255
 
256
256
  def test_lstm(self, bldg_ix: int, training_data: pd.DataFrame, schema_filepath: Path) -> Tuple[int, pd.DataFrame]:
257
257
  # set data
258
- schema = read_json(schema_filepath)
258
+ schema = FileHandler.read_json(schema_filepath)
259
259
  schema_directory = Path(schema_filepath).parents[0]
260
260
  bldg_key = list(schema['buildings'].keys())[bldg_ix]
261
261
  dynamics_model = schema['buildings'][bldg_key]['dynamics']
@@ -511,7 +511,7 @@ class Neighborhood:
511
511
 
512
512
  schema_filepath = os.path.join(schema_directory, f'schema.json')
513
513
  template = user_customization_function(template) if user_customization_function is not None else template
514
- write_json(schema_filepath, template)
514
+ FileHandler.write_json(schema_filepath, template)
515
515
 
516
516
  return schema_filepath
517
517
 
@@ -4,7 +4,7 @@ import numpy as np
4
4
  from sklearn.tree import DecisionTreeClassifier
5
5
  from citylearn.base import Environment
6
6
  from citylearn.data import LogisticRegressionOccupantParameters
7
- from citylearn.utilities import read_pickle
7
+ from citylearn.utilities import FileHandler
8
8
 
9
9
  class Occupant(Environment):
10
10
  def __init__(self, **kwargs) -> None:
@@ -48,12 +48,12 @@ class LogisticRegressionOccupant(Occupant):
48
48
  @setpoint_increase_model_filepath.setter
49
49
  def setpoint_increase_model_filepath(self, value: Union[Path, str]):
50
50
  self.__setpoint_increase_model_filepath = value
51
- self.__setpoint_increase_model = read_pickle(self.setpoint_increase_model_filepath)
51
+ self.__setpoint_increase_model = FileHandler.read_pickle(self.setpoint_increase_model_filepath)
52
52
 
53
53
  @setpoint_decrease_model_filepath.setter
54
54
  def setpoint_decrease_model_filepath(self, value: Union[Path, str]):
55
55
  self.__setpoint_decrease_model_filepath = value
56
- self.__setpoint_decrease_model = read_pickle(self.setpoint_decrease_model_filepath)
56
+ self.__setpoint_decrease_model = FileHandler.read_pickle(self.setpoint_decrease_model_filepath)
57
57
 
58
58
  @delta_output_map.setter
59
59
  def delta_output_map(self, value: Mapping[Union[str, int], float]):
@@ -0,0 +1,145 @@
1
+ import pickle
2
+ from typing import Any
3
+ import simplejson as json
4
+ import yaml
5
+
6
+ class FileHandler:
7
+ @staticmethod
8
+ def read_json(filepath: str, **kwargs) -> dict:
9
+ """Return JSON document as dictionary.
10
+
11
+ Parameters
12
+ ----------
13
+ filepath : str
14
+ pathname of JSON document.
15
+
16
+ Other Parameters
17
+ ----------------
18
+ **kwargs : dict
19
+ Other infrequently used keyword arguments to be parsed to `simplejson.load`.
20
+
21
+ Returns
22
+ -------
23
+ dict
24
+ JSON document converted to dictionary.
25
+ """
26
+
27
+ with open(filepath) as f:
28
+ json_file = json.load(f, **kwargs)
29
+
30
+ return json_file
31
+
32
+ @staticmethod
33
+ def write_json(filepath: str, dictionary: dict, **kwargs):
34
+ """Write dictionary to JSON file.
35
+
36
+ Parameters
37
+ ----------
38
+ filepath : str
39
+ pathname of JSON document.
40
+ dictionary: dict
41
+ dictionary to convert to JSON.
42
+
43
+ Other Parameters
44
+ ----------------
45
+ **kwargs : dict
46
+ Other infrequently used keyword arguments to be parsed to `simplejson.dump`.
47
+ """
48
+
49
+ kwargs = {'ignore_nan': True, 'sort_keys': False, 'default': str, 'indent': 2, **kwargs}
50
+
51
+ with open(filepath,'w') as f:
52
+ json.dump(dictionary, f, **kwargs)
53
+
54
+ @staticmethod
55
+ def read_yaml(filepath: str) -> dict:
56
+ """Return YAML document as dictionary.
57
+
58
+ Parameters
59
+ ----------
60
+ filepath : str
61
+ pathname of YAML document.
62
+
63
+ Returns
64
+ -------
65
+ dict
66
+ YAML document converted to dictionary.
67
+ """
68
+
69
+ with open(filepath, 'r') as f:
70
+ data = yaml.safe_load(f)
71
+
72
+ return data
73
+
74
+ @staticmethod
75
+ def write_yaml(filepath: str, dictionary: dict, **kwargs):
76
+ """Write dictionary to YAML file.
77
+
78
+ Parameters
79
+ ----------
80
+ filepath : str
81
+ pathname of YAML document.
82
+ dictionary: dict
83
+ dictionary to convert to YAML.
84
+
85
+ Other Parameters
86
+ ----------------
87
+ **kwargs : dict
88
+ Other infrequently used keyword arguments to be parsed to `yaml.safe_dump`.
89
+ """
90
+
91
+ kwargs = {'sort_keys': False, 'indent': 2, **kwargs}
92
+
93
+ with open(filepath, 'w') as f:
94
+ yaml.safe_dump(dictionary, f, **kwargs)
95
+
96
+ @staticmethod
97
+ def read_pickle(filepath: str, **kwargs) -> Any:
98
+ """Return pickle file as some Python class object.
99
+
100
+ Parameters
101
+ ----------
102
+ filepath : str
103
+ pathname of pickle file.
104
+
105
+ Other Parameters
106
+ ----------------
107
+ **kwargs : dict
108
+ Other infrequently used keyword arguments to be parsed to `pickle.load`.
109
+
110
+ Returns
111
+ -------
112
+ Any
113
+ Pickle file as a Python object.
114
+ """
115
+
116
+ with (open(filepath, 'rb')) as f:
117
+ data = pickle.load(f, **kwargs)
118
+
119
+ return data
120
+
121
+ @staticmethod
122
+ def write_pickle(filepath: str, data: Any, **kwargs):
123
+ """Write Python object to pickle file.
124
+
125
+ Parameters
126
+ ----------
127
+ filepath : str
128
+ pathname of pickle document.
129
+ data: dict
130
+ object to convert to pickle.
131
+
132
+ Other Parameters
133
+ ----------------
134
+ **kwargs : dict
135
+ Other infrequently used keyword arguments to be parsed to `pickle.dump`.
136
+ """
137
+
138
+ with open(filepath, 'wb') as f:
139
+ pickle.dump(data, f, **kwargs)
140
+
141
+ @staticmethod
142
+ def join_url(*args: str) -> str:
143
+ url = '/'.join([a.strip('/') for a in args])
144
+
145
+ return url
@@ -1 +0,0 @@
1
- __version__ = '2.3.0'
@@ -1,138 +0,0 @@
1
- import pickle
2
- from typing import Any
3
- import simplejson as json
4
- import yaml
5
-
6
- def read_json(filepath: str, **kwargs) -> dict:
7
- """Return JSON document as dictionary.
8
-
9
- Parameters
10
- ----------
11
- filepath : str
12
- pathname of JSON document.
13
-
14
- Other Parameters
15
- ----------------
16
- **kwargs : dict
17
- Other infrequently used keyword arguments to be parsed to `simplejson.load`.
18
-
19
- Returns
20
- -------
21
- dict
22
- JSON document converted to dictionary.
23
- """
24
-
25
- with open(filepath) as f:
26
- json_file = json.load(f, **kwargs)
27
-
28
- return json_file
29
-
30
- def write_json(filepath: str, dictionary: dict, **kwargs):
31
- """Write dictionary to JSON file.
32
-
33
- Parameters
34
- ----------
35
- filepath : str
36
- pathname of JSON document.
37
- dictionary: dict
38
- dictionary to convert to JSON.
39
-
40
- Other Parameters
41
- ----------------
42
- **kwargs : dict
43
- Other infrequently used keyword arguments to be parsed to `simplejson.dump`.
44
- """
45
-
46
- kwargs = {'ignore_nan': True, 'sort_keys': False, 'default': str, 'indent': 2, **kwargs}
47
-
48
- with open(filepath,'w') as f:
49
- json.dump(dictionary, f, **kwargs)
50
-
51
- def read_yaml(filepath: str) -> dict:
52
- """Return YAML document as dictionary.
53
-
54
- Parameters
55
- ----------
56
- filepath : str
57
- pathname of YAML document.
58
-
59
- Returns
60
- -------
61
- dict
62
- YAML document converted to dictionary.
63
- """
64
-
65
- with open(filepath, 'r') as f:
66
- data = yaml.safe_load(f)
67
-
68
- return data
69
-
70
- def write_yaml(filepath: str, dictionary: dict, **kwargs):
71
- """Write dictionary to YAML file.
72
-
73
- Parameters
74
- ----------
75
- filepath : str
76
- pathname of YAML document.
77
- dictionary: dict
78
- dictionary to convert to YAML.
79
-
80
- Other Parameters
81
- ----------------
82
- **kwargs : dict
83
- Other infrequently used keyword arguments to be parsed to `yaml.safe_dump`.
84
- """
85
-
86
- kwargs = {'sort_keys': False, 'indent': 2, **kwargs}
87
-
88
- with open(filepath, 'w') as f:
89
- yaml.safe_dump(dictionary, f, **kwargs)
90
-
91
- def read_pickle(filepath: str, **kwargs) -> Any:
92
- """Return pickle file as some Python class object.
93
-
94
- Parameters
95
- ----------
96
- filepath : str
97
- pathname of pickle file.
98
-
99
- Other Parameters
100
- ----------------
101
- **kwargs : dict
102
- Other infrequently used keyword arguments to be parsed to `pickle.load`.
103
-
104
- Returns
105
- -------
106
- Any
107
- Pickle file as a Python object.
108
- """
109
-
110
- with (open(filepath, 'rb')) as f:
111
- data = pickle.load(f, **kwargs)
112
-
113
- return data
114
-
115
- def write_pickle(filepath: str, data: Any, **kwargs):
116
- """Write Python object to pickle file.
117
-
118
- Parameters
119
- ----------
120
- filepath : str
121
- pathname of pickle document.
122
- data: dict
123
- object to convert to pickle.
124
-
125
- Other Parameters
126
- ----------------
127
- **kwargs : dict
128
- Other infrequently used keyword arguments to be parsed to `pickle.dump`.
129
- """
130
-
131
- with open(filepath, 'wb') as f:
132
- pickle.dump(data, f, **kwargs)
133
-
134
- @staticmethod
135
- def join_url(*args: str) -> str:
136
- url = '/'.join([a.strip('/') for a in args])
137
-
138
- return url
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes