New answers tagged

0 votes

Why does CPython has both C and .python versions of modules?

C code is real code, python is interface code. The c code is the performant code, while the python is for python runtime to correctly handle call sites. Also use the c code Version to get the most ...
user avatar
  • 82
0 votes

Best practices for naming python utils / extending core modules?

Very rarely, I'll add a module that re-exports various utilities I'll need throughout the project, so that in every file I can do from .prelude import * and get all those utilities or definitions in ...
user avatar
  • 123k
0 votes

What is a good way to call a unit-tested function provided by a library/package?

Foo is a dependency. If you want to test it, import it and call the methods on it that are being used as part of your test suite. For example, if you are using Foo.X write some tests around the X ...
user avatar
  • 10.6k
1 vote
Accepted

What is a good way to call a unit-tested function provided by a library/package?

Encapsulating library functions makes most sense when your "own" interface main offers simplified access to the library, or at least provides a more precise or more readable name (assuming ...
user avatar
  • 184k
3 votes
Accepted

Properly "exposing" a variable from a class in Python

A class becoming "bloated" is not a good reason to expose internal data if the methods are still cohesive. While a large class can indicate it is doing too much, is is not an automatic ...
user avatar
2 votes

TL suggests that testing, refactor, and tool usage could avoid the need for verbose logging

The reason you're depending on this verbose logging is that you need to be able to make sense of the flow of the code. Therefore, the flow must logically be very complex and/or cluttered without this ...
user avatar
  • 37.3k
1 vote

TL suggests that testing, refactor, and tool usage could avoid the need for verbose logging

The alternative to verbose logging is (obviously) limited logging - and this is really only helpful when you can look at what you do log and pinpoint the exact cause of the problem you're trying to ...
user avatar
  • 4,360
1 vote

How to properly isolate tests for dataframes with grouping?

More generally what you are describing is a Data-Driven Test. To echo Kilian Foth's comment, each data frame is not a separate test case. Each data frame represents a different input to the same test ...
user avatar
2 votes
Accepted

How to use lazy import to speed up a list of known types in python?

The easiest solution is indeed going to be to describe the model via strings describing the module that you then import. For example, something like: import importlib KNOWN_TYPES = { "kmeans&...
user avatar
  • 123k
0 votes
Accepted

Python - Brainstorming: How would you compare texts and find differences?

I'd have a look at the Levenshtein algorithm (install using pip install Levenshtein) on a word level: import Levenshtein, re pattern = r"[\w']+|[.,!?;]" def words(s): return re.findall(...
user avatar

Top 50 recent answers are included