Part II of my beginner's guide on building clean Python ML/AI projects is out! 🏗️ A codebase without strict rules inevitably turns into an inconsistent mess. But with properly configured static code analyzers, you can block bad code before it's even committed. This article is primarily tailored for Data Scientists and ML Engineers - SWE colleagues already know these basics inside out entirely I suppose :) . Here is the essential toolkit I cover: 🔹 Linting & Formatting: Catching Python anti-patterns at lightning speed. 🔹 Type Checkers: Why they are crucial (and some code quirk example from HuggingFace Transformers library). 🔹 Pre-commit & CI/CD: How to enforce strict checks pipeline to ensure messy code never reaches your main branch. Links to the full article: 🔗 Medium (EN): https://lnkd.in/dXTA7jQb 🔗 Substack (EN): https://lnkd.in/dwDmY6cK 🔗 Teletype (RU): https://lnkd.in/dG7hfTwK #Python #MLOps #MachineLearning #CleanCode #StaticAnalysis #Ruff #mypy #ty #Pyright #Pyrefly
Python ML/AI Project Clean Code with Static Analysis
More Relevant Posts
-
There is something very powerful in Python that you can unlock by implementing just 2 methods. __𝙡𝙚𝙣__ __𝙜𝙚𝙩𝙞𝙩𝙚𝙢__ For example, if you implement this: 𝗰𝗹𝗮𝘀𝘀 𝗗𝗲𝗰𝗸: 𝗱𝗲𝗳 __𝗶𝗻𝗶𝘁__(𝘀𝗲𝗹𝗳, 𝗰𝗮𝗿𝗱𝘀): 𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀 = 𝗰𝗮𝗿𝗱𝘀 𝗱𝗲𝗳 __𝗹𝗲𝗻__(𝘀𝗲𝗹𝗳): 𝗿𝗲𝘁𝘂𝗿𝗻 𝗹𝗲𝗻(𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀) 𝗱𝗲𝗳 __𝗴𝗲𝘁𝗶𝘁𝗲𝗺__(𝘀𝗲𝗹𝗳, 𝗽𝗼𝘀𝗶𝘁𝗶𝗼𝗻): 𝗿𝗲𝘁𝘂𝗿𝗻 𝘀𝗲𝗹𝗳.𝗰𝗮𝗿𝗱𝘀[𝗽𝗼𝘀𝗶𝘁𝗶𝗼𝗻] Your object automatically supports: • 𝗹𝗲𝗻(𝘥𝘦𝘤𝘬) • 𝘥𝘦𝘤𝘬[0] • slicing → 𝘥𝘦𝘤𝘬[:3] • iteration → 𝗳𝗼𝗿 𝘤𝘢𝘳𝘥 𝗶𝗻 𝘥𝘦𝘤𝘬 • 𝗶𝗻 operator • 𝗿𝗮𝗻𝗱𝗼𝗺.𝗰𝗵𝗼𝗶𝗰𝗲(𝘥𝘦𝘤𝘬) • 𝘀𝗼𝗿𝘁𝗲𝗱(𝘥𝘦𝘤𝘬) You didn’t implement: • iteration • slicing • search • random selection Python gave you all of that. That takeaway is: If your object behaves like a sequence, Implement __𝗹𝗲𝗻__ + __𝗴𝗲𝘁𝗶𝘁𝗲𝗺__ and let Python do the rest. Don’t build features. Plug into the Data Model. #python #datamodel #dunder #magicmethods #__len__ #__getitem__
To view or add a comment, sign in
-
🚀 Day 19/60 – Iterators (Understand How Python Loops Work Internally ⚡) Yesterday you learned Decorators. Today, let’s go deeper into how Python actually loops 👇 🧠 What is an Iterator? An iterator is an object that lets you loop through data one item at a time. 👉 Implements __iter__() and __next__() 👉 Used behind every for loop 🔄 How for loop works internally numbers = [1, 2, 3] iterator = iter(numbers) print(next(iterator)) # 1 print(next(iterator)) # 2 print(next(iterator)) # 3 👉 StopIteration is raised at the end ⚡ Custom Iterator class CountUp: def __init__(self, max): self.max = max self.current = 1 def __iter__(self): return self def __next__(self): if self.current > self.max: raise StopIteration val = self.current self.current += 1 return val for num in CountUp(5): print(num) 🔍 Iterator vs Iterable 👉 Iterable → Object you can loop over (list, tuple, string) 👉 Iterator → Object that actually produces values 🔥 Why Iterators Matter? ✅ Memory efficient ✅ Lazy evaluation ✅ Core of generators ❌ Common Mistake Confusing iterable with iterator ❌ 👉 Not every iterable is an iterator 🔥 Pro Tip 👉 Use iter() to convert iterable → iterator 👉 Use next() to manually fetch values 🔥 Challenge for today 👉 Create a custom iterator 👉 That returns numbers from 1 to 3 👉 Use next() manually Comment “DONE” when finished ✅ Follow Adeel Sajjad to stay consistent for 60 days 🚀 #Python #PythonProgramming #LearnPython #Coding #Programming #Developer
To view or add a comment, sign in
-
-
Unlocking the Power of Strings in Python! 🐍✨ Today’s focus on my Python journey was all about understanding and manipulation—specifically, Strings. It’s incredible how much logic depends on effectively handling text data! Here are my key takeaways from today's deep dive: ✂️ String Slicing: Mastering the [start:stop:step] syntax. It feels like precision surgery for text data—extracting exactly what you need, whether it's a prefix, a suffix, or a reversed substring. 🚫 String Immutability (Mutation): A crucial realization! You can’t change a string in place. Trying to do word[0] = 'C' will throw an error. Understanding this forces you to think correctly about creating new modified strings instead of trying to mutate existing ones. 🛠️ String Methods: My toolbox just got a lot bigger. I explored powerful built-in functions like: .strip() for cleaning up whitespace. .replace() for quick swaps. .split() and .join() for converting between strings and lists. .upper(), .lower(), .capitalize() for formatting. Understanding these fundamentals is making my code cleaner and more efficient. Every day is a step closer to building complex applications! #Python #CodingJourney #Strings #DataManipulation #SoftwareDevelopment #ContinuousLearning #WebDev #Backend #ProgrammingFundamentals #CleanCode #LearningToCode
To view or add a comment, sign in
-
-
🚀 Day 4 of #14DaysOfPython 🐍 Today’s focus: Strings (Core Concepts) — working with text in Python. 💡 Easy way to understand strings: 🔹 Why strings? 👉 Almost every real-world program deals with text (names, inputs, data processing) 💡 Core Concepts (Logic First): 🔹 String Indexing & Slicing 👉 Access characters using position s[0] → first character s[-1] → last character s[start:end] → substring 🔹 String Traversal 👉 Loop through characters for loop → simple iteration while loop → more control 🔹 Built-in Methods 👉 Modify strings easily lower(), upper() → case change strip() → remove spaces replace() → replace characters 🔹 ASCII Basics 👉 Convert between characters and numbers ord('A') → 65 chr(65) → 'A' 🧠 Problems I practiced: Palindrome check Reverse a string Count vowels & consonants Remove spaces from a string ✨ Key takeaway: Strings are not just text — they are data you can manipulate step-by-step using logic. Day 4 done ✅ Moving to Day 5 💪 #HackerRank #Python #ProblemSolving #CodingJourney #Developer #LearningInPublic #codegnan
To view or add a comment, sign in
-
-
I have been spending more time working with pandas in Python, and honestly, I didn’t realize how powerful it actually is. What started as basic data cleaning slowly turned into understanding how easily large datasets can be transformed, filtered, and structured with just a few lines of code. I’ve been exploring things like: → handling messy data → grouping and aggregations → preparing datasets before analysis And it’s starting to change how I look at data — not just from a reporting side, but how it’s actually processed behind the scenes. Still learning, but definitely enjoying the process of uncovering what pandas can really do. #Python #Pandas #DataAnalytics #Learning #DataEngineering
To view or add a comment, sign in
-
Ever tried to "fix" a value inside a `for` loop while zipping, only to find the original list unchanged? 🤔 Let's break down why. This is a classic Python iterator deep dive. When you zip lists, you create an iterator yielding tuples. The loop variable is just a reference to the current tuple element, not a pointer back into the list. **Key Mechanics:** - `zip()` produces an immutable tuple for each iteration. - Reassigning the loop variable simply points that variable to a new object; it does not mutate the original list. - The loop variable is a local name within the loop's scope, separate from the list's indices. **Takeaway:** To modify the original list, you need to access it by index, or use a list comprehension/map. Direct assignment to the iteration variable only rebinds the name. Understanding this distinction between names, references, and mutability is crucial for mastering Python's data model. It’s not a bug—it’s a feature of clean, predictable iteration. #Python #ProgrammingLogic #MorningCode #SoftwareEngineering #TechDeepDive What’s a similar "aha!" moment you’ve had with iterators or variable scoping?
To view or add a comment, sign in
-
i->SLOW DRIFT MATCH<-!i “RIEMANN” VERSUS “THE PYTHON” 4 of 4 Total from both competitors after 4 rounds “Riemann & the Monty Python”. 100 punches thrown/56 landed from Riemann through 4 rounds and 150 punches thrown/ 111 punches landed!!! HOWEVER!i… Multiple points were taken off from the unnecessary 256 bytes to Riemann from the Monty Python. Beyond the Alert: Using Riemannian Logic to Catch Data Drift -First 2 rounds "fences" (tiered thresholds). /3rd and 4th rounds we’re all about the "flow." 🌊 In high-velocity data, a single breach is often just noise. The real danger is “Slow Drift”—a persistent, subtle climb that indicates a systemic failure. To catch this, I’ve integrated a "Phase 2" logic that takes inspiration from Riemannian Geometry. The Logic: Instead of viewing data as a flat list, we treat it as a curved space. By calculating the Riemannian Distance between our current "rolling average" and our historical baseline, we can detect when the "geometry" of our performance is starting to warp. Why it works: * Riemann Sums for Trends: We use discrete data "slices" to approximate a continuous trend line, catching shifts before they ever hit the red zone. * Predictive Awareness: We aren't just asking "is it broken?" We are measuring the “drift” relative to our "Critical Line"—the 1.0001 threshold. Data isn't static; it’s a landscape. If you aren't measuring the curves, you’re missing half the story. 📈🚀 Result Riemann was the clear winner after all the point deductions. Don’t tell Monty! bye byee!!! 4 of 4
To view or add a comment, sign in
-
Python is the backbone of most AI systems. Models, data, APIs and automation, most of it runs through Python. That is why the ecosystem matters more than the syntax. Different parts of AI rely on different tools: • Data prep → Pandas • Model building → TensorFlow • Visualization → Matplotlib / Seaborn • Data collection → BeautifulSoup / Selenium • Serving models → FastAPI / Flask • Full systems → Django • Vision tasks → OpenCV AI is a pipeline. And Python sits across that entire pipeline. If you understand how these pieces connect, you move from scripts to systems.
To view or add a comment, sign in
-
-
🚀 Solved another problem on LeetCode: Concatenation of Array Today I worked on a simple yet important array problem that focuses on understanding how data structures behave in Python. Problem Summary: Given an integer array "nums", create a new array "ans" such that: 👉 "ans = nums + nums" (i.e., the array is repeated twice) 💡 My Approach: I used Python’s built-in list concatenation: "return nums + nums" ⚡ Why this approach is best? - No loops required - Clean and readable code - Uses optimized internal operations 📊 Complexity Analysis: • Time Complexity: O(n) • Space Complexity: O(n) 🔁 Comparison with other approaches: 🔸 Using loops → More lines of code, less readable 🔸 Using append() → Slightly slower due to repeated operations 🔸 Using list comprehension → Still less direct My approach is the most efficient and pythonic way to solve this problem. 🧠Key Learning: Sometimes the simplest solution is the most powerful. Knowing built-in operations can save time and improve code quality. Consistency in DSA is the key 🔥 #LeetCode #DSA #Python #CodingJourney #ProblemSolving #Code
To view or add a comment, sign in
-
-
Finally moved Python & AI project from local to live! 🎈 I’ve been experimenting with Python lately and finished building a simple Personal Assistant for my morning routines and productivity. It was fun to step outside .NET and try out some new tools: ⚡ Groq : Really impressed with how fast the responses are. 🐍 Python: Getting more comfortable with the syntax every day. 🖥️ Streamlit: Made it super easy to put a clean UI on top. It’s work in progress, but you can check out V1 here: https://lnkd.in/gwyuaGZt #Python #Streamlit #PersonalProject #BuildingInPublic #WomenInCode
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development