Skip to content

Instantly share code, notes, and snippets.

View noklam's full-sized avatar
🎯
Focusing

Nok Lam Chan noklam

🎯
Focusing
View GitHub Profile
@noklam
noklam / __init__.py
Created April 2, 2024 23:07
%load_node for kedro 0.18 series, replace kedro/ipython/__init__.py
"""
This script creates an IPython extension to load Kedro-related variables in
local scope.
"""
from __future__ import annotations
import inspect
import logging
import os
@noklam
noklam / gist:d45764cb97b997e8c8d0565e6d914006
Created February 1, 2024 13:58
Get Python function body without the signatures
def _prepare_function_body(func: Callable) -> str:
# https://stackoverflow.com/questions/38050649/getting-a-python-functions-source-code-without-the-definition-lines
all_source_lines = inspect.getsourcelines(func)[0]
# Remove any decorators
func_lines = dropwhile(lambda x: x.startswith("@"), all_source_lines)
line: str = next(func_lines).strip()
if not line.startswith("def "):
return line.rsplit(",")[0].strip()
# Handle functions that are not one-liners
first_line = next(func_lines)
@noklam
noklam / kedro_debug.py
Last active September 6, 2023 12:40
A handy script for debugging Kedro Project to print all necessary information - inspired by https://github.com/fastai/fastai1/blob/master/fastai/utils/show_install.py
def show_install(show_nvidia_smi: bool = False):
"Print user's setup information"
import kedro, kedro_datasets, platform, os, sys
rep = []
opt_mods = []
rep.append(["=== Software ===", None])
rep.append(["python", platform.python_version()])
@noklam
noklam / softfail_runner.py
Created June 28, 2023 13:39
softfail_runner.py
"""``SequentialRunner`` is an ``AbstractRunner`` implementation. It can be
used to run the ``Pipeline`` in a sequential manner using a topological sort
of provided nodes.
"""
from collections import Counter
from itertools import chain
from typing import Any, Dict, Set
from kedro.io import DataCatalog
@noklam
noklam / experiment_omegaconf_merge.py
Created March 24, 2023 19:25
An example to understand how merging work with omegaconf
# Experiment 2 - Simplified Merge Config Case
%%writefile base.yml
# conf/local/parameters.yaml
client:
url: http://${host}:${server.port}/
server_port: ${server.port}
%%writefile local.yml
# Here you can define all your data sets by using simple YAML syntax.
#
# Documentation for this file format can be found in "The Data Catalog"
# Link: https://kedro.readthedocs.io/en/stable/data/data_catalog.html
#
# We support interacting with a variety of data stores including local file systems, cloud, network and HDFS
#
# An example data set definition can look as follows:
#
#bikes:
@noklam
noklam / index.html
Created December 26, 2020 14:28
Simple Search bar with vue - React Clone
<div id="app">
@noklam
noklam / lightgbm_bug_trains.py
Created November 18, 2020 06:42
lightgbm_bug_trains.py
# TRAINS - Example of LightGBM integration
#
import lightgbm as lgb
import pandas as pd
from sklearn.metrics import mean_squared_error
from trains import Task
task = Task.init(project_name="examples", task_name="LIGHTgbm")
@noklam
noklam / pandas_join_nearest_key.py
Last active August 14, 2020 01:58
Join nearest key for time series pandas dataframe
# # Using pandas merge_as_of (similar to a merge join) to do inexact join (join the nearest key instead)
import pandas as pd
# %%
table_a = pd.DataFrame([('2020-01-01'), ('2020-01-03'), ('2020-01-06')],
columns=['PK'])
table_b = pd.DataFrame([('2020-01-01', 'A'), ('2020-01-02', 'A'),
('2020-01-04', 'B'), ('2020-01-05', 'B')],
columns=['FK', 'Category'])
# %%
@noklam
noklam / wandb-example.ipynb
Created June 17, 2020 09:24
wandb-example.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.